网络层

This commit is contained in:
2025-06-28 17:38:22 +08:00
parent 54dc7ba173
commit 605197345b
20 changed files with 482 additions and 376 deletions

View File

@@ -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
}