コード例 #1
0
ファイル: RpcServer.cs プロジェクト: lxshwyan/Socean.Rpc
        private static void ProcessReceive(ITransport serverTransport, FrameData frameData,
                                           IMessageProcessor messageProcessor)
        {
            byte[] responseContent = null;
            byte   responseCode    = 0;

            try
            {
                var response = Process(frameData.Title, frameData.ContentBytes, messageProcessor);

                responseContent = response.Bytes;
                responseCode    = response.Code;
            }
            catch
            {
                responseCode = ResponseErrorCode.SERVER_INTERNAL_ERROR;
            }

            try
            {
                if (NetworkSettings.TcpRequestSendMode == TcpSendMode.Async)
                {
                    if (responseCode != 0)
                    {
                        serverTransport.AsyncSend(string.Empty, FrameFormat.EmptyBytes, responseCode, frameData.MessageId);
                    }
                    else
                    {
                        serverTransport.AsyncSend(string.Empty, responseContent, 0, frameData.MessageId);
                    }
                }
                else
                {
                    if (responseCode != 0)
                    {
                        serverTransport.Send(string.Empty, FrameFormat.EmptyBytes, responseCode, frameData.MessageId);
                    }
                    else
                    {
                        serverTransport.Send(string.Empty, responseContent, 0, frameData.MessageId);
                    }
                }
            }
            catch
            {
                serverTransport.Close();
                return;
            }
        }