Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // websocket连接已关闭 ErrWsConnClose = errors.New("websocket connection closed") // websocket唯一连接id不能为空 ErrIdEmpty = errors.New("id is null") )
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection interface { Set(id string, wsConn *websocket.Conn) error Get(id string) (wsConn *websocket.Conn, err error) GetGroup(groupName string) (wsConnList []*websocket.Conn, err error) GetAll() (wsConnList []*websocket.Conn, err error) Del(id string) error }
客户端维护的websocket在线连接接口
type WsConnection ¶
type WsConnection struct {
// contains filtered or unexported fields
}
WsConnection表示维护的一个websocket类型
func NewWsConnection ¶
func NewWsConnection(id string, collect Collection) *WsConnection
新建一个WsConnection连接. id为唯一连接id; collect为实现Collection接口类
func (*WsConnection) Close ¶
func (conn *WsConnection) Close() error
func (*WsConnection) Open ¶
func (conn *WsConnection) Open(w http.ResponseWriter, r *http.Request) error
func (*WsConnection) Receive ¶
func (conn *WsConnection) Receive() (msg *WsMessage, err error)
func (*WsConnection) Write ¶
func (conn *WsConnection) Write(msg *WsMessage) (err error)
Click to show internal directories.
Click to hide internal directories.