Documentation
¶
Index ¶
- Constants
- Variables
- type CloseCode
- type Conn
- func (c *Conn) Close()
- func (c *Conn) FlushWriter()
- 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) WriteBatch(opcode Opcode, payload []byte)
- func (c *Conn) WriteClose(code CloseCode, 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
- type Request
- type Storage
- type Upgrader
Constants ¶
Variables ¶
View Source
var ( ErrCheckOrigin = errors.New("check origin error") ErrHandshake = errors.New("handshake error") )
Functions ¶
This section is empty.
Types ¶
type CloseCode ¶ added in v1.1.0
type CloseCode uint16
const ( // 正常关闭; 无论为何目的而创建, 该链接都已成功完成任务. CloseNormalClosure CloseCode = 1000 // 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开. CloseGoingAway CloseCode = 1001 // 由于协议错误而中断连接. CloseProtocolError CloseCode = 1002 // 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据). CloseUnsupported CloseCode = 1003 // 保留. 表示没有收到预期的状态码. CloseNoStatusReceived CloseCode = 1005 // 保留. 用于期望收到状态码时连接非正常关闭 (也就是说, 没有发送关闭帧). CloseAbnormalClosure CloseCode = 1006 // 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据). CloseUnsupportedData CloseCode = 1007 // 由于收到不符合约定的数据而断开连接. 这是一个通用状态码, 用于不适合使用 1003 和 1009 状态码的场景. ClosePolicyViolation CloseCode = 1008 // 由于收到过大的数据帧而断开连接. CloseMessageTooLarge CloseCode = 1009 // 客户端期望服务器商定一个或多个拓展, 但服务器没有处理, 因此客户端断开连接. CloseMissingExtension CloseCode = 1010 // 客户端由于遇到没有预料的情况阻止其完成请求, 因此服务端断开连接. CloseInternalServerErr CloseCode = 1011 // 服务器由于重启而断开连接. [Ref] CloseServiceRestart CloseCode = 1012 // 服务器由于临时原因断开连接, 如服务器过载因此断开一部分客户端连接. [Ref] CloseTryAgainLater CloseCode = 1013 // 保留. 表示连接由于无法完成 TLS 握手而关闭 (例如无法验证服务器证书). CloseTLSHandshake CloseCode = 1015 )
type Conn ¶
type Conn struct {
// Concurrent Variable
// store session information
*Storage
// contains filtered or unexported fields
}
func (*Conn) FlushWriter ¶ added in v1.1.0
func (c *Conn) FlushWriter()
FlushWriter 刷新写入缓冲区 flush write buffer
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) WriteBatch ¶ added in v1.1.0
WriteBatch write message in batch, call FlushWriter in the end 批量写入消息,最后一次写入后需要调用FlushWriter
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 Message ¶
type Message struct {
// contains filtered or unexported fields
}
type Upgrader ¶
type Upgrader struct {
// whether to compress data, dv = false
CompressEnabled bool
// compress level eg: flate.BestSpeed
CompressLevel int
// websocket handshake timeout, dv=3s
HandshakeTimeout time.Duration
// max message size, dv=1024*1024 (1MiB)
MaxContentLength int
// read frame timeout, dv=5s
ReadTimeout time.Duration
// write frame timeout, dv=5s
WriteTimeout time.Duration
// filter user request
CheckOrigin func(r *Request) bool
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.