Пример #1
0
        private void CompleteMessage(Socket handler, int threadId, byte[] message)
        {
            // For server, notify the server to do something
            if (!_useClientMultiplexer)
            {
                var receivedMessage = _receiveMessagePool.Pop();
                receivedMessage.Socket   = handler;
                receivedMessage.ThreadId = threadId;
                receivedMessage.Message  = message;

                var messageReceived = MessageReceived;
                if (messageReceived != null)
                {
                    var messageReceivedArgs = new MessageReceivedArgs(receivedMessage);
                    messageReceived(this, messageReceivedArgs);
                }
                return;
            }

            // For client, set and signal multiplexer
            var multiplexerData = GetMultiplexerData(threadId);

            multiplexerData.Message = message;

            SignalMultiplexer(threadId);
        }
Пример #2
0
        private void ReceiveMessage(object sender, MessageReceivedArgs e)
        {
            var command = e.ReceivedMessage.Message;
            if (command == null || command.Length == 0)
            {
                return;
            }

            // Get the command string
            int position = 0;
            var commandString = DacheProtocolHelper.CommunicationEncoding.GetString(DacheProtocolHelper.Extract(command, ref position));

            var commandResult = ProcessCommand(commandString, command, position); 
            if (commandResult != null) 
            { 
                // Send the result if there is one 
                _server.Reply(commandResult, e.ReceivedMessage); 
            } 
        }
Пример #3
0
        private void ReceiveMessage(object sender, MessageReceivedArgs e)
        {
            var command = e.ReceivedMessage.Message;
            if (command == null || command.Length == 0)
            {
                _logger.Error("Dache.CacheHost.Communication.CacheHostServer.ReceiveMessage - command is null or empty", "command variable is null or empty, indicating an empty or invalid message");
                return;
            }

            // Parse out the command byte
            DacheProtocolHelper.MessageType messageType;
            command.ExtractControlByte(out messageType);
            // Get the command string skipping our control byte
            var commandString = DacheProtocolHelper.CommunicationEncoding.GetString(command, 1, command.Length - 1);
            var commandResult = ProcessCommand(commandString, messageType);
            if (commandResult != null)
            {
                // Send the result if there is one
                _server.Reply(commandResult, e.ReceivedMessage);
            }
        }