public override void OnReceived(ITcpSession session, IDynamicBuffer dataBuffer) { int cmd = dataBuffer.Buffer[0]; MemoryStream ms = new MemoryStream(dataBuffer.Buffer, 1, dataBuffer.DataSize - 1); switch (cmd) { case 1: { RpcCallData data = Serializer.Deserialize <RpcCallData>(ms); ThreadPool.QueueUserWorkItem(CallFunc, new CallStatus() { Session = session, Data = data }); } break; case 2: { var data = Serializer.Deserialize <RpcReturnData>(ms); RpcFactory.GetInvoke(session.SessionId).ReturnData(data); } break; default: { var data = Serializer.Deserialize <RpcErrorInfo>(ms); RpcFactory.GetInvoke(session.SessionId).ReturnError(data); } break; } ms.Dispose(); }
public static RpcProxy GetProxy <T>(this ITcpSession session, string impName = null) where T : class { if (session == null) { throw new Exception("session Can't be empty"); } if (string.IsNullOrEmpty(impName)) { impName = typeof(T).Name; } var proxy = new RpcProxy(typeof(T), impName); ProxyFactory fac = session.SessionData.Get("proxyfactory") as ProxyFactory; proxy.RpcInvoke = fac.GetInvoke(session.SessionId); return(proxy); }