Documentation
¶
Index ¶
Constants ¶
View Source
const ( // Ping ping Ping = "ping" // Pong pong Pong = "pong" )
Variables ¶
View Source
var ( // ErrConnClose 连接已关闭 ErrConnClose = errors.New("connection already closed") )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
// Close 关闭连接
Close() error
// Open 开启连接
Open(w http.ResponseWriter, r *http.Request) error
// Receive 接收数据
Receive() (msg *Message, err error)
// Write 写入数据
Write(msg *Message) (err error)
}
Conn 长连接接口
type Connection ¶ added in v0.1.1
type Connection struct {
// contains filtered or unexported fields
}
Connection 维护的长连接.
func NewConnection ¶ added in v0.1.1
func NewConnection(heartBeater Heartbeat) *Connection
NewConnection 新建Connection实例.
func (*Connection) GetConnID ¶ added in v0.1.1
func (c *Connection) GetConnID() string
GetConnID 获取连接ID
func (*Connection) Open ¶ added in v0.1.1
func (c *Connection) Open(w http.ResponseWriter, r *http.Request) error
Open 开启连接
func (*Connection) Receive ¶ added in v0.1.1
func (c *Connection) Receive() (msg *Message, err error)
Receive 接收数据
func (*Connection) Write ¶ added in v0.1.1
func (c *Connection) Write(msg *Message) (err error)
Write 写入数据
type Heartbeat ¶ added in v0.1.5
type Heartbeat interface {
// IsPingMsg 校验是否Ping
IsPingMsg(msg []byte) bool
// GetPongMsg 获取服务端->客户端Pong请求数据
GetPongMsg() []byte
// GetAliveTime 获取连接活跃时间(秒)如果两次心跳大于这个有效时间连接将断开
GetAliveTime() int
}
Heartbeat 业务方实现维持心跳的接口
type Message ¶ added in v0.1.1
type Message struct {
// MessageType The message types are defined in RFC 6455, section 11.8.
MessageType int
// Data 消息内容
Data []byte
}
Message 定义了一个消息实体.
Click to show internal directories.
Click to hide internal directories.
