Ejemplo n.º 1
0
        private void RemoteRequest(int source, string method, NetSprotoType.ClusterClientRequest request, long connectionId, int session)
        {
            int      tag      = NetProtocol.GetInstance().GetTag("RPC");
            RPCParam rpcParam = new RPCParam();

            rpcParam.method = request.method;
            rpcParam.param  = request.param;

            if (m_totalRemoteSession >= Int32.MaxValue)
            {
                m_totalRemoteSession = 0;
            }
            int           remoteSession = ++m_totalRemoteSession;
            List <byte[]> buffers       = m_skynetPacketManager.PackSkynetRequest(request.remoteService, remoteSession, tag, rpcParam.encode());

            SSContext rpcContext = new SSContext();

            rpcContext.LongDict["ConnectionId"]     = connectionId;
            rpcContext.IntegerDict["RemoteSession"] = remoteSession;
            rpcContext.IntegerDict["SourceSession"] = session;
            rpcContext.IntegerDict["Source"]        = source;
            rpcContext.StringDict["Method"]         = method;

            RPCResponseContext rpcResponseCallback = new RPCResponseContext();

            rpcResponseCallback.Callback = RemoteResponseCallback;
            rpcResponseCallback.Context  = rpcContext;
            m_remoteResponseCallbacks.Add(remoteSession, rpcResponseCallback);

            Dictionary <int, WaitForResponseRequest> waitResponseDict = null;
            bool isExist = m_conn2sessions.TryGetValue(connectionId, out waitResponseDict);

            if (!isExist)
            {
                waitResponseDict = new Dictionary <int, WaitForResponseRequest>();
                m_conn2sessions.Add(connectionId, waitResponseDict);
            }

            WaitForResponseRequest waitForResponseRequest = new WaitForResponseRequest();

            waitForResponseRequest.Session = session;
            waitForResponseRequest.Source  = source;
            waitResponseDict.Add(remoteSession, waitForResponseRequest);

            NetworkPacket networkPacket = new NetworkPacket();

            networkPacket.ConnectionId = connectionId;
            networkPacket.TcpObjectId  = m_tcpObjectId;
            networkPacket.Buffers      = buffers;
            networkPacket.Type         = SocketMessageType.DATA;

            NetworkPacketQueue.GetInstance().Push(networkPacket);
        }
Ejemplo n.º 2
0
        private void ProcessRemoteResponse(int remoteSession, byte[] param, RPCError errorCode)
        {
            RPCResponseContext responseCallback = null;
            bool isExist = m_remoteResponseCallbacks.TryGetValue(remoteSession, out responseCallback);

            if (isExist)
            {
                responseCallback.Callback(responseCallback.Context, "RemoteResponseCallback", param, errorCode);
                m_remoteResponseCallbacks.Remove(remoteSession);
            }
            else
            {
                LoggerHelper.Info(m_serviceAddress, string.Format("ClusterServer SocketData unknow remoteSession:{0}", remoteSession));
            }
        }