Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Handler websocket.Handler = func(conn *websocket.Conn) { c := &Conn{ C: conn, } m.Lock() c.ID = index connections[index] = c index++ m.Unlock() OnConnect(c) var ( data []byte err error ) for { err = websocket.Message.Receive(c.C, &data) if err != nil { OnError(c, err) break } OnMessage(c, data) } m.Lock() delete(connections, c.ID) m.Unlock() }
Handler 最重要的入口
View Source
var OnConnect func(*Conn)
OnConnect 当客户端与服务端建立WebSocket连接时触发的回调函数,每个连接只会触发一次
View Source
var OnError func(*Conn, error)
OnError 当客户端的连接上发生错误时触发,特别注意:客户端断开连接也是触发本函数
View Source
var OnMessage func(*Conn, []byte)
OnMessage 当客户端通过连接发来数据时触发的回调函数
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.