Documentation
¶
Index ¶
- type BaseRouter
- type Client
- type IRouter
- type Server
- func (h *Server) Close()
- func (h *Server) Online() int
- func (h *Server) Range(f func(c *Client) bool)
- func (h *Server) SendToAll(message []byte)
- func (h *Server) SendToAllJson(obj interface{})
- 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()
- func (h *Server) WaitCloseSignal(before, after func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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()
func (*BaseRouter) OnServerUpdate ¶
func (b *BaseRouter) OnServerUpdate()
type Client ¶
type Client struct {
//chanClose chan bool
Server *Server //server对线
User interface{} //用户对象
UserData sync.Map //保存一些用户自定义内容
ConnectionIndex int //
LastMsgTime time.Time //最后收到消息时间
Ip string //登录IP
WsMessageType int //websocket的协议类型,1:text, 2:binary
// contains filtered or unexported fields
}
Client 保存客户端连接和用户
type IRouter ¶
type IRouter interface {
OnMessage(c *Client, msgType int, message []byte) // OnMessage 1:text, 2:Binary
OnDisconnect(c *Client) // OnDisconnect hub协成中调用
OnServerClose() // 关闭服务器执行一次
OnServerUpdate() //
OnConnected(c *Client) //
}
IRouter 方法2: 接口
type Server ¶
type Server struct {
ConnectionIndex int64 //连接计数
// contains filtered or unexported fields
}
func NewZZServer ¶
func NewZZServer() *Server
func (*Server) SetGinEngine ¶ added in v1.2.2
func (*Server) SetMessageType ¶ added in v1.2.7
SetMessageType websocket的协议类型,1:text, 2:binary
默认值:websocket.TextMessage 可选: websocket.BinaryMessage
func (*Server) SetWebsocketPort ¶ added in v1.2.2
func (*Server) SetWsPath ¶ added in v1.2.6
func (h *Server) SetTCPPort(port int) {
h.tcpPort = port
}
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.