//Connect,Disconnect,Dispatch use member TcpSocket todo? public void SendRequest(string proto, SprotoObject request = null, ProtoDispatcher.MessageHandler handler = null) { Int64 session_id = 0; if (handler != null) { this.session_id = this.session_id + 1; session_id = this.session_id; this.sessions.Add(session_id, handler); } Int64 message_id = this.gen_message_id(); RpcPackage package = this.Proto.PackRequest(proto, request, session_id, message_id); this.TcpSocket.Send(package.data, package.size); }
//Connect,Disconnect,Dispatch use member TcpSocket todo? public void SendRequest(string proto, SprotoObject request = null, ProtoDispatcher.MessageHandler handler = null) { // string msg = String.Format("[{0}] op=SendRequest,proto={1},tag={2},ud={3},session={4},type={5},request={6},response={7}", // this.TcpSocket.Name,proto,0,0,0,request.type,0,0); // this._Log(msg); Int64 session_id = 0; if (handler != null) { this.session_id = this.session_id + 1; session_id = this.session_id; this.sessions.Add(session_id, handler); } Int64 message_id = this.gen_message_id(); RpcPackage package = this.Proto.PackRequest(proto, request, session_id, message_id); this.TcpSocket.Send(package.data, package.size); }
private void _OnMessage(TcpClientSocket tcpSocket, byte[] data, int size) { RpcMessage Message = this.Proto.UnpackMessage(data, size); string msg = String.Format("[{0}] op=OnMessage,proto={1},tag={2},ud={3},session={4},type={5},request={6},response={7}", this.TcpSocket.Name, Message.proto, Message.tag, Message.ud, Message.session, Message.type, Message.request, Message.response); this._Log(msg); if (Message.type == "response") { Int64 session = Message.session; ProtoDispatcher.MessageHandler handler = null; if (!this.sessions.TryGetValue(session, out handler)) { return; } handler(this, Message); return; } this.Dispatcher.Dispatch(this, Message); }