Documentation
¶
Index ¶
- Variables
- type BaseRouter
- type Client
- func (c *Client) Close()
- func (c *Client) GetIP() string
- func (c *Client) GetRemoteAddr() string
- func (c *Client) LastMsgTime() time.Time
- func (c *Client) Send(msgType int, data []byte)
- func (c *Client) SendByte(data []byte)
- func (c *Client) SendJson(obj interface{}) error
- func (c *Client) SendText(msg string)
- type IRouter
- type Server
- func (h *Server) Close()
- func (h *Server) GetClient(id int) (*Client, bool)
- func (h *Server) Online() (int, bool)
- func (h *Server) Range(f func(c *Client) bool) bool
- func (h *Server) SendToAll(message []byte)
- func (h *Server) SetCheckOrigin(fn func(*http.Request) bool)
- func (h *Server) SetGinEngine(g *gin.Engine)
- func (h *Server) SetMessageType(t int)
- func (h *Server) SetRouter(r IRouter)
- func (h *Server) SetWebsocketPort(port int)
- func (h *Server) SetWsPath(path string)
- func (h *Server) Start() error
- func (h *Server) WaitCloseSignal(before, after func())
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRouterNotSet = errors.New("zzserver: please set router via SetRouter()") ErrPortNotSet = errors.New("zzserver: please set websocket port via SetWebsocketPort()") ErrHubOpTimeout = errors.New("zzserver: hub operation timeout") ErrAlreadyStarted = errors.New("zzserver: server already started") )
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
BaseRouter 用于嵌入,这样就不需要实现所有方法
func (*BaseRouter) OnConnected ¶
func (b *BaseRouter) OnConnected(c *Client)
func (*BaseRouter) OnDisconnect ¶
func (b *BaseRouter) OnDisconnect(c *Client)
func (*BaseRouter) OnMessage ¶
func (b *BaseRouter) OnMessage(c *Client, msgType int, message []byte)
func (*BaseRouter) OnServerClose ¶
func (b *BaseRouter) OnServerClose()
type Client ¶
type Client struct {
Server *Server
User interface{} // 业务用户对象,登录后绑定
ConnectionIndex int
Ip string // 解析代理头后的登录 IP
WsMessageType int // 默认发送类型:websocket.TextMessage 或 websocket.BinaryMessage
// contains filtered or unexported fields
}
Client 保存客户端连接和用户
func (*Client) LastMsgTime ¶
LastMsgTime 返回最后收到消息或 Pong 的时间(并发安全)。
type Server ¶
type Server struct {
ConnectionIndex int64
// contains filtered or unexported fields
}
func NewZZServer ¶
func NewZZServer() *Server
func (*Server) Close ¶
func (h *Server) Close()
Close 优雅关闭:停止 HTTP 监听 → OnServerClose → 断开所有客户端 → 停止 hub。 注意:OnServerClose 在所有客户端断开之前执行。
func (*Server) SetCheckOrigin ¶ added in v1.4.0
SetCheckOrigin 设置 WebSocket 跨域校验;默认允许所有来源。
func (*Server) SetGinEngine ¶ added in v1.2.2
func (*Server) SetMessageType ¶ added in v1.2.7
SetMessageType 设置默认发送类型(TextMessage 或 BinaryMessage);接收类型由每条消息的 msgType 决定。
func (*Server) SetWebsocketPort ¶ added in v1.2.2
func (*Server) WaitCloseSignal ¶ added in v1.2.3
func (h *Server) WaitCloseSignal(before, after func())
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
json
command
|
|
|
protobuf/client
command
|
|
|
protobuf/server
command
|
|
|
protobuf/warptest
command
|
Click to show internal directories.
Click to hide internal directories.