sinking_websocket

package module
v0.0.0-...-c4b74be Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*websocket.Conn
}

Conn conn 包装

type Error

type Error struct {
	ErrCode int
	ErrMsg  string
}

func (*Error) Error

func (err *Error) Error() string

type WebSocket

type WebSocket struct {
	Id        string
	OnError   func(id string, err error)
	OnConnect func(id string, ws *Conn)
	OnClose   func(id string, err error)
	OnMessage func(id string, ws *Conn, messageType int, data []byte)
}

WebSocket 执行

func NewWebSocket

func NewWebSocket() *WebSocket

NewWebSocket 单例

func (*WebSocket) Listen

func (handle *WebSocket) Listen(writer http.ResponseWriter, request *http.Request, responseHeader http.Header)

func (*WebSocket) SetCloseHandle

func (handle *WebSocket) SetCloseHandle(fun func(id string, err error)) *WebSocket

func (*WebSocket) SetConnectHandle

func (handle *WebSocket) SetConnectHandle(fun func(id string, ws *Conn)) *WebSocket

func (*WebSocket) SetErrorHandle

func (handle *WebSocket) SetErrorHandle(fun func(id string, err error)) *WebSocket

func (*WebSocket) SetId

func (handle *WebSocket) SetId(id string) *WebSocket

func (*WebSocket) SetOnMessageHandle

func (handle *WebSocket) SetOnMessageHandle(fun func(id string, ws *Conn, messageType int, data []byte)) *WebSocket

type WebSocketConnections

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

WebSocketConnections ws连接用户

func NewWebSocketConnections

func NewWebSocketConnections() *WebSocketConnections

NewWebSocketConnections 单例

func (*WebSocketConnections) Delete

func (connections *WebSocketConnections) Delete(key string) bool

Delete 删除长连接对象

func (*WebSocketConnections) Get

func (connections *WebSocketConnections) Get(key string) *Conn

Get 获取长连接对象

func (*WebSocketConnections) GetAll

func (connections *WebSocketConnections) GetAll() map[string]*Conn

GetAll 获取所有长连接对象

func (*WebSocketConnections) Set

func (connections *WebSocketConnections) Set(key string, conn *Conn)

Set 设置长连接对象

Jump to

Keyboard shortcuts

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