Documentation
¶
Index ¶
- type Config
- type Conn
- func (c *Conn) Listen()
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time)
- func (c *Conn) SetReadDeadline(t time.Time)
- func (c *Conn) SetWriteDeadline(t time.Time)
- func (c *Conn) WriteClose(code uint16, reason []byte)
- func (c *Conn) WriteMessage(opcode Opcode, payload []byte)
- func (c *Conn) WritePing(payload []byte)
- func (c *Conn) WritePong(payload []byte)
- type Event
- type Message
- type Opcode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.2.0
type Config struct {
// whether to compress data
CompressEnabled bool
// compress level eg: flate.BestSpeed
CompressLevel int
// max message size
MaxContentLength int
// whether to check utf8 encoding, disabled for better performance
CheckTextEncoding bool
// client authentication
Authenticate func(r *internal.Request) bool
}
type Conn ¶
type Conn struct {
// Concurrent Variable
// store session information
*internal.SessionStorage
// contains filtered or unexported fields
}
func Accept ¶ added in v1.2.0
func Accept(ctx context.Context, w http.ResponseWriter, r *http.Request, eventHandler Event, config Config) (*Conn, error)
Accept http protocol upgrade to websocket ctx done means server stopping
func (*Conn) Listen ¶ added in v1.1.2
func (c *Conn) Listen()
Listen listening to websocket messages through a dead loop 通过死循环监听websocket消息
func (*Conn) RemoteAddr ¶ added in v1.0.1
func (*Conn) SetReadDeadline ¶ added in v1.1.2
SetReadDeadline sets read deadline
func (*Conn) SetWriteDeadline ¶ added in v1.1.2
SetWriteDeadline sets write deadline
func (*Conn) WriteClose ¶
WriteClose write close frame 发送关闭帧
func (*Conn) WriteMessage ¶ added in v1.1.0
WriteMessage write text/binary message text message must be utf8 encoding 发送文本/二进制消息, 文本消息必须是utf8编码
type Event ¶ added in v1.1.2
type Event interface {
OnOpen(socket *Conn)
OnError(socket *Conn, err error)
OnClose(socket *Conn, code uint16, reason []byte)
OnPing(socket *Conn, payload []byte)
OnPong(socket *Conn, payload []byte)
OnMessage(socket *Conn, message *Message)
}
WebSocket Event OnError and OnClose will not both be called
Source Files
¶
Click to show internal directories.
Click to hide internal directories.