package socket import ( "time" ) type Action int const ( // None indicates that no action should occur following an event. None Action = iota // Close closes the connection. Close // Shutdown shutdowns the engine. 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 // 收到消息 OnPong(ISocketConn) OnClose(ISocketConn, error) Action // 关闭连接 OnTick() (time.Duration, Action) } // ISocketConn 由网络层实现 type ISocketConn interface { GetParam(key string) interface{} SetParam(key string, values interface{}) RemoteAddr() string Ping() error // 需要隔一段时间调用一下,建议20s Write(data []byte) error Close() error IsClose() bool }