ws

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHandler

func DefaultHandler(ctx *Context) string

DefaultHandler

func GetUpgradeConnection

func GetUpgradeConnection(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

GetUpgradeConnection get web socket connection

Types

type Client

type Client struct {
	// unique id
	ID string

	// connection
	Conn *websocket.Conn

	// 处理方法
	Handler IHandler

	// 连接时的回调
	OpenHandler func()

	// 关闭时的回调
	CloseHandler func()

	// 扩展字段
	Extends map[string]interface{}
	// contains filtered or unexported fields
}

Client is a websocket client

func NewClient

func NewClient(conn *websocket.Conn, handler IHandler) *Client

NewClient return Client

func (*Client) Listen

func (c *Client) Listen()

Listen 监听

func (*Client) OnClose

func (c *Client) OnClose()

OnClose

func (*Client) OnOpen

func (c *Client) OnOpen()

OnConnect

func (*Client) SendMessage

func (c *Client) SendMessage(message []byte)

SendMessage

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context 采用上下文的方式传递

func (*Context) Get

func (ctx *Context) Get(key string) interface{}

Get

func (*Context) GetMessage

func (ctx *Context) GetMessage() string

GetMessage

func (*Context) Set

func (ctx *Context) Set(key string, value interface{})

Set

type IClient

type IClient interface {
	OnOpen()
	OnClose()
	Listen()
	SendMessage(message []byte)
}

IClient

type IHandler

type IHandler func(ctx *Context) string

type Manager

type Manager interface {
	// register client
	RegisterClient(client *Client)

	// unregister client
	UnregisterClient(client *Client)

	// broadcast message
	Broadcast(message string)

	// send message
	Send(message []byte, ignore *Client)

	Start()
}

Manager ws管理器接口

func NewManager

func NewManager() Manager

NewManager define a ws server manager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL