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 ) // ISocketServer 由应用层实现 type ISocketServer interface { OnOpen(ISocketConn) ([]byte, Action) // 开启连接 OnHandShake(ISocketConn) // 开始握手 OnMessage(ISocketConn, []byte) Action // 收到消息 OnClose(ISocketConn, error) Action // 关闭连接 OnTick() (time.Duration, Action) } // ISocketConn 由网络层实现 type ISocketConn interface { GetParam(key string) string SetParam(key string, values string) Write(data []byte) error Close() error }