网络层
This commit is contained in:
@@ -15,19 +15,33 @@ const (
|
||||
Shutdown
|
||||
)
|
||||
|
||||
type OpCode byte
|
||||
|
||||
const (
|
||||
OpContinuation OpCode = 0x0
|
||||
OpText OpCode = 0x1
|
||||
OpBinary OpCode = 0x2
|
||||
OpClose OpCode = 0x8
|
||||
OpPing OpCode = 0x9
|
||||
OpPong OpCode = 0xa
|
||||
)
|
||||
|
||||
// ISocketServer 由应用层实现
|
||||
type ISocketServer interface {
|
||||
OnOpen(ISocketConn) ([]byte, Action) // 开启连接
|
||||
OnHandShake(ISocketConn) // 开始握手
|
||||
OnMessage(ISocketConn, []byte) Action // 收到消息
|
||||
OnClose(ISocketConn, error) Action // 关闭连接
|
||||
OnPong(ISocketConn)
|
||||
OnClose(ISocketConn, error) Action // 关闭连接
|
||||
OnTick() (time.Duration, Action)
|
||||
}
|
||||
|
||||
// ISocketConn 由网络层实现
|
||||
type ISocketConn interface {
|
||||
GetParam(key string) string
|
||||
SetParam(key string, values string)
|
||||
GetParam(key string) interface{}
|
||||
SetParam(key string, values interface{})
|
||||
RemoteAddr() string
|
||||
Ping() error // 需要隔一段时间调用一下,建议20s
|
||||
Write(data []byte) error
|
||||
Close() error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user