Documentation
¶
Index ¶
- Variables
- func ClientDemo()
- func ServerDemo()
- type Client
- type ClientIns
- func (my *ClientIns) Close()
- func (my *ClientIns) GetClient(clientName string) (*Client, bool)
- func (*ClientIns) New(insName string) *ClientIns
- func (my *ClientIns) SendMsgByName(clientName string, msgType int, msg []byte) ([]byte, error)
- func (my *ClientIns) SetClient(clientName, host, path string, ...) (*Client, error)
- type ClientPool
- func (*ClientPool) Close()
- func (*ClientPool) CloseClient(insName, clientName string) error
- func (*ClientPool) GetClient(insName, clientName string) *Client
- func (*ClientPool) GetClientIns(insName string) (*ClientIns, bool)
- func (*ClientPool) Once() *ClientPool
- func (*ClientPool) SendMsgByName(insName, clientName string, msgType int, msg []byte) ([]byte, error)
- func (*ClientPool) SetClient(insName, clientName, host, path string, ...) (*Client, error)
- func (*ClientPool) SetClientIns(insName string) (*ClientIns, error)
- func (*ClientPool) SetOnCloseClientWrong(fn func(insName, clientName string, err error)) *ClientPool
- func (*ClientPool) SetOnConnect(fn func(insName, clientName string)) *ClientPool
- func (*ClientPool) SetOnConnectWrong(fn func(insName, clientName string, err error)) *ClientPool
- func (*ClientPool) SetOnReceiveMsgWrong(fn func(insName, clientName string, propertyMessage []byte, err error)) *ClientPool
- func (*ClientPool) SetOnSendMsgWrong(fn func(insName, clientName string, err error)) *ClientPool
- type Heart
- type MessageTimeout
- type PendingRequest
- type ResponseWrt
- type Server
- type ServerIns
- 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(onCloseConnectionWrong func(conn *websocket.Conn, err error)) *ServerPool
- func (*ServerPool) SetOnConnect(onConnect func(*websocket.Conn)) *ServerPool
- func (*ServerPool) SetOnConnectErr(onConnectWrong func(error)) *ServerPool
- func (*ServerPool) SetOnPing(fn func(*websocket.Conn)) *ServerPool
- func (*ServerPool) SetOnReceiveMsg(onMessage func(*websocket.Conn, []byte) string) *ServerPool
- func (*ServerPool) SetOnReceiveMsgErr(onMessageWrong func(*websocket.Conn, error)) *ServerPool
- func (*ServerPool) SetOnRouterErr(onRouterWrong func(*websocket.Conn, error)) *ServerPool
- func (*ServerPool) SetOnSendMsgErr(onSendMessageWrong func(conn *websocket.Conn, err error)) *ServerPool
Constants ¶
This section is empty.
Variables ¶
var ( HeartOpt Heart MessageTimeoutOpt MessageTimeout )
var APP struct { ServerPool ServerPool ServerIns ServerIns MessageTimeout MessageTimeout Heart Heart Client Client ClientIns ClientIns ClientPool ClientPool }
var MsgType msgType
Functions ¶
func ClientDemo ¶
func ClientDemo()
func ServerDemo ¶
func ServerDemo()
Types ¶
type Client ¶
Client websocket 客户端链接
func NewClient ¶
func NewClient( insName, name, host, path string, receiveMessageFunc func(insName, clientName string, prototypeMsg []byte) ([]byte, error), ) (*Client, error)
NewClient 实例化:websocket 客户端链接
type ClientIns ¶
ClientIns websocket 客户端链接实例
func (*ClientIns) SendMsgByName ¶
SendMsgByName 发送消息:通过名称
type ClientPool ¶
type ClientPool struct {
Error error
// contains filtered or unexported fields
}
ClientPool websocket 客户端连接池
func (*ClientPool) CloseClient ¶
func (*ClientPool) CloseClient(insName, clientName string) error
CloseClient 关闭链接
func (*ClientPool) GetClient ¶
func (*ClientPool) GetClient(insName, clientName string) *Client
GetClient 获取客户端链接
func (*ClientPool) GetClientIns ¶
func (*ClientPool) GetClientIns(insName string) (*ClientIns, bool)
GetClientIns 获取链接实例
func (*ClientPool) Once ¶
func (*ClientPool) Once() *ClientPool
func (*ClientPool) SendMsgByName ¶
func (*ClientPool) SendMsgByName(insName, clientName string, msgType int, msg []byte) ([]byte, error)
SendMsgByName 发送消息:通过名称
func (*ClientPool) SetClient ¶
func (*ClientPool) SetClient( insName, clientName, host, path string, receiveMessageFn func(insName, clientName string, prototypeMsg []byte) ([]byte, error), heart *Heart, timeout *MessageTimeout, ) (*Client, error)
SetClient 设置websocket客户端链接
func (*ClientPool) SetClientIns ¶
func (*ClientPool) SetClientIns(insName string) (*ClientIns, error)
SetClientIns 设置实例链接
func (*ClientPool) SetOnCloseClientWrong ¶
func (*ClientPool) SetOnCloseClientWrong(fn func(insName, clientName string, err error)) *ClientPool
SetOnCloseClientWrong 设置回调:关闭客户端链接错
func (*ClientPool) SetOnConnect ¶
func (*ClientPool) SetOnConnect(fn func(insName, clientName string)) *ClientPool
SetOnConnect 设置回调:成功创建链接
func (*ClientPool) SetOnConnectWrong ¶
func (*ClientPool) SetOnConnectWrong(fn func(insName, clientName string, err error)) *ClientPool
SetOnConnectWrong 设置回调:链接错误
func (*ClientPool) SetOnReceiveMsgWrong ¶
func (*ClientPool) SetOnReceiveMsgWrong(fn func(insName, clientName string, propertyMessage []byte, err error)) *ClientPool
SetOnReceiveMsgWrong 设置回调:接收消息错误
func (*ClientPool) SetOnSendMsgWrong ¶
func (*ClientPool) SetOnSendMsgWrong(fn func(insName, clientName string, err error)) *ClientPool
SetOnSendMsgWrong 设置回调:发送消息错误
type Heart ¶
type Heart struct {
// contains filtered or unexported fields
}
Heart 链接心跳
var HeartApp Heart
func (*Heart) SetInterval ¶
SetInterval 设置定时器
type MessageTimeout ¶
type MessageTimeout struct {
// contains filtered or unexported fields
}
MessageTimeout 通信超时
func DefaultMessageTimeout ¶
func DefaultMessageTimeout() *MessageTimeout
DefaultMessageTimeout 默认消息超时:5秒
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 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(onCloseConnectionWrong 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(onConnectWrong 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(onMessageWrong func(*websocket.Conn, error)) *ServerPool
SetOnReceiveMsgErr 设置回调:接收消息失败
func (*ServerPool) SetOnRouterErr ¶
func (*ServerPool) SetOnRouterErr(onRouterWrong func(*websocket.Conn, error)) *ServerPool
SetOnRouterErr 设置回调:路由解析失败
func (*ServerPool) SetOnSendMsgErr ¶
func (*ServerPool) SetOnSendMsgErr(onSendMessageWrong func(conn *websocket.Conn, err error)) *ServerPool
SetOnSendMsgErr 设置回调:发送消息失败