Documentation
¶
Index ¶
- Variables
- func ClientDemo()
- func ServerDemo()
- type Client
- type ClientInstance
- type ClientPool
- func (ClientPool) Close()
- func (ClientPool) CloseClient(instanceName, clientName string) error
- func (ClientPool) GetClient(instanceName, clientName string) *Client
- func (ClientPool) GetClientInstance(instanceName string) (*ClientInstance, bool)
- func (ClientPool) SendMsgByName(instanceName, clientName string, msgType int, msg []byte) ([]byte, error)
- func (ClientPool) SetClient(instanceName, clientName, host, path string, ...) (*Client, error)
- func (ClientPool) SetClientInstance(instanceName string) (*ClientInstance, error)
- func (ClientPool) SetOnCloseClientErr(fn func(instanceName, clientName string, err error)) *ClientPool
- func (ClientPool) SetOnConnect(fn func(instanceName, clientName string)) *ClientPool
- func (ClientPool) SetOnConnectErr(fn func(instanceName, clientName string, err error)) *ClientPool
- func (ClientPool) SetOnReceiveMsgErr(fn func(instanceName, clientName string, propertyMessage []byte, err error)) *ClientPool
- func (ClientPool) SetOnSendMsgErr(fn func(instanceName, clientName string, err error)) *ClientPool
- type Heart
- type MessageTimeout
- type PendingRequest
- type ResponseWrt
- type Server
- type ServerInstance
- type ServerPool
- func (ServerPool) Close()
- func (ServerPool) Handle(writer http.ResponseWriter, req *http.Request, header http.Header, ...)
- func (ServerPool) Once() *ServerPool
- func (ServerPool) RegisterRouter(routerKey string, fn func(ws *websocket.Conn)) *ServerPool
- func (ServerPool) SendMsgByAccountOpenId(accountOpenId string, message []byte) error
- func (ServerPool) SendMsgByWsConn(ws *websocket.Conn, message []byte) error
- func (ServerPool) SendMsgByWsManyConn(servers *array.AnyArray[*Server], message []byte)
- func (ServerPool) SetOnCloseConnErr(onCloseConnectionErr func(conn *websocket.Conn, err error)) *ServerPool
- func (ServerPool) SetOnConnect(onConnect func(*websocket.Conn)) *ServerPool
- func (ServerPool) SetOnConnectErr(onConnectErr func(error)) *ServerPool
- func (ServerPool) SetOnPing(fn func(*websocket.Conn)) *ServerPool
- func (ServerPool) SetOnReceiveMsg(onMessage func(*websocket.Conn, []byte) string) *ServerPool
- func (ServerPool) SetOnReceiveMsgErr(onMessageErr func(*websocket.Conn, error)) *ServerPool
- func (ServerPool) SetOnRouterErr(onRouterErr func(*websocket.Conn, error)) *ServerPool
- func (ServerPool) SetOnSendMsgErr(onSendMessageErr func(conn *websocket.Conn, err error)) *ServerPool
Constants ¶
This section is empty.
Variables ¶
var ( HeartOpt Heart MessageTimeoutOpt MessageTimeout )
var ( ServerPoolApp ServerPool SeverInstanceApp ServerInstance )
var MsgType msgType
Functions ¶
func ClientDemo ¶
func ClientDemo()
func ServerDemo ¶
func ServerDemo()
Types ¶
type Client ¶
type Client struct {
InstanceName, Name string
Conn *websocket.Conn
// contains filtered or unexported fields
}
Client websocket 客户端链接
type ClientInstance ¶
ClientInstance websocket 客户端链接实例
func NewClientInstance ¶ added in v1.2.3
func NewClientInstance(instanceName string) *ClientInstance
NewClientInstance 实例化:websocket 客户端实例
func (*ClientInstance) GetClient ¶
func (my *ClientInstance) GetClient(clientName string) (*Client, bool)
GetClient 获取websocket客户端链接
func (*ClientInstance) SendMsgByName ¶
SendMsgByName 发送消息:通过名称
type ClientPool ¶
type ClientPool struct { Error error // contains filtered or unexported fields }
ClientPool websocket 客户端连接池
func OnceClientPool ¶ added in v1.2.3
func OnceClientPool() *ClientPool
OnceClientPool 单例化:websocket 客户端连接池
func (ClientPool) CloseClient ¶
func (ClientPool) CloseClient(instanceName, clientName string) error
CloseClient 关闭链接
func (ClientPool) GetClient ¶
func (ClientPool) GetClient(instanceName, clientName string) *Client
GetClient 获取客户端链接
func (ClientPool) GetClientInstance ¶
func (ClientPool) GetClientInstance(instanceName string) (*ClientInstance, bool)
GetClientInstance 获取链接实例
func (ClientPool) SendMsgByName ¶
func (ClientPool) SendMsgByName(instanceName, clientName string, msgType int, msg []byte) ([]byte, error)
SendMsgByName 发送消息:通过名称
func (ClientPool) SetClient ¶
func (ClientPool) SetClient( instanceName, clientName, host, path string, receiveMessageFn func(instanceName, clientName string, prototypeMsg []byte) ([]byte, error), heart *Heart, timeout *MessageTimeout, ) (*Client, error)
SetClient 设置websocket客户端链接
func (ClientPool) SetClientInstance ¶
func (ClientPool) SetClientInstance(instanceName string) (*ClientInstance, error)
SetClientInstance 设置实例链接
func (ClientPool) SetOnCloseClientErr ¶
func (ClientPool) SetOnCloseClientErr(fn func(instanceName, clientName string, err error)) *ClientPool
SetOnCloseClientErr 设置回调:关闭客户端链接错
func (ClientPool) SetOnConnect ¶
func (ClientPool) SetOnConnect(fn func(instanceName, clientName string)) *ClientPool
SetOnConnect 设置回调:成功创建链接
func (ClientPool) SetOnConnectErr ¶
func (ClientPool) SetOnConnectErr(fn func(instanceName, clientName string, err error)) *ClientPool
SetOnConnectErr 设置回调:链接错误
func (ClientPool) SetOnReceiveMsgErr ¶
func (ClientPool) SetOnReceiveMsgErr(fn func(instanceName, clientName string, propertyMessage []byte, err error)) *ClientPool
SetOnReceiveMsgErr 设置回调:接收消息错误
func (ClientPool) SetOnSendMsgErr ¶
func (ClientPool) SetOnSendMsgErr(fn func(instanceName, clientName string, err error)) *ClientPool
SetOnSendMsgErr 设置回调:发送消息错误
type Heart ¶
type Heart struct {
// contains filtered or unexported fields
}
Heart 链接心跳
func (*Heart) SetInterval ¶
SetInterval 设置定时器
type MessageTimeout ¶
type MessageTimeout struct {
// contains filtered or unexported fields
}
MessageTimeout 通信超时
func DefaultMessageTimeout ¶ added in v1.2.3
func DefaultMessageTimeout() *MessageTimeout
DefaultMessageTimeout 默认消息超时:5秒
func NewMessageTimeout ¶ added in v1.2.3
func NewMessageTimeout() *MessageTimeout
NewMessageTimeout 实例化:链接超时
func (*MessageTimeout) SetInterval ¶
func (r *MessageTimeout) SetInterval(interval time.Duration) *MessageTimeout
SetInterval 设置定时器时间
type PendingRequest ¶
PendingRequest 待处理请求
type ResponseWrt ¶
type ResponseWrt struct{}
func (ResponseWrt) Header ¶
func (ResponseWrt) Header() http.Header
func (ResponseWrt) WriteHeader ¶
func (ResponseWrt) WriteHeader(statusCode int)
type ServerInstance ¶
ServerInstance websocket服务端实例
type ServerPool ¶
type ServerPool struct {
// contains filtered or unexported fields
}
ServerPool websocket 服务端连接池
func (ServerPool) Handle ¶
func (ServerPool) Handle( writer http.ResponseWriter, req *http.Request, header http.Header, condition func() (string, bool), )
Handle 消息处理
func (ServerPool) RegisterRouter ¶
func (ServerPool) RegisterRouter(routerKey string, fn func(ws *websocket.Conn)) *ServerPool
RegisterRouter 注册路由
func (ServerPool) SendMsgByAccountOpenId ¶
func (ServerPool) SendMsgByAccountOpenId(accountOpenId string, message []byte) error
SendMsgByAccountOpenId 根据用户openId发送消息
func (ServerPool) SendMsgByWsConn ¶
func (ServerPool) SendMsgByWsConn(ws *websocket.Conn, message []byte) error
SendMsgByWsConn 通过链接发送消息
func (ServerPool) SendMsgByWsManyConn ¶
func (ServerPool) SendMsgByWsManyConn(servers *array.AnyArray[*Server], message []byte)
SendMsgByWsManyConn 通过链接切片发送消息
func (ServerPool) SetOnCloseConnErr ¶
func (ServerPool) SetOnCloseConnErr(onCloseConnectionErr func(conn *websocket.Conn, err error)) *ServerPool
SetOnCloseConnErr 设置回调:关闭链接错误
func (ServerPool) SetOnConnect ¶
func (ServerPool) SetOnConnect(onConnect func(*websocket.Conn)) *ServerPool
SetOnConnect 设置回调:链接成功后
func (ServerPool) SetOnConnectErr ¶
func (ServerPool) SetOnConnectErr(onConnectErr func(error)) *ServerPool
SetOnConnectErr 设置回调:链接失败后
func (ServerPool) SetOnPing ¶
func (ServerPool) SetOnPing(fn func(*websocket.Conn)) *ServerPool
SetOnPing 设置回调:ping
func (ServerPool) SetOnReceiveMsg ¶
func (ServerPool) SetOnReceiveMsg(onMessage func(*websocket.Conn, []byte) string) *ServerPool
SetOnReceiveMsg 设置回调:接收消息
func (ServerPool) SetOnReceiveMsgErr ¶
func (ServerPool) SetOnReceiveMsgErr(onMessageErr func(*websocket.Conn, error)) *ServerPool
SetOnReceiveMsgErr 设置回调:接收消息失败
func (ServerPool) SetOnRouterErr ¶
func (ServerPool) SetOnRouterErr(onRouterErr func(*websocket.Conn, error)) *ServerPool
SetOnRouterErr 设置回调:路由解析失败
func (ServerPool) SetOnSendMsgErr ¶
func (ServerPool) SetOnSendMsgErr(onSendMessageErr func(conn *websocket.Conn, err error)) *ServerPool
SetOnSendMsgErr 设置回调:发送消息失败