예제 #1
0
        public void SendMessage(BaseMessage message)
        {
            var wrappedMessage = MessageSerializer.SerializeAndWrapMessage(message);

            logger.Debug("[ClientNetworkComponent] Sending: {message}", Encoding.UTF8.GetString(wrappedMessage, 0, wrappedMessage.Length));
            Send(socket, wrappedMessage);
        }
예제 #2
0
        internal void SendMessage(Socket handler, BaseMessage message)
        {
            var messageData = MessageSerializer.SerializeAndWrapMessage(message);

            try
            {
                handler.BeginSend(messageData, 0, messageData.Length, SocketFlags.None, new AsyncCallback(SendCallback), handler);
            }
            catch (Exception e)
            {
                throw new CommunicationErrorException(CommunicationExceptionType.InvalidSocket, e);
            }
        }
예제 #3
0
        public void UnwrapMessages_ShouldSeparateMessages()
        {
            var messagesCount   = messages.Count;
            var bytesCount      = 0;
            var wrappedMessages = new byte[(1 << 13) - 2];

            foreach (var message in messages)
            {
                var wrapped = MessageSerializer.SerializeAndWrapMessage(message);

                Array.Copy(wrapped, 0, wrappedMessages, bytesCount, wrapped.Length);
                bytesCount += wrapped.Length;
            }

            var unwrappedMessages = MessageSerializer.UnwrapMessages(wrappedMessages, bytesCount).ToList();

            Assert.AreEqual(messagesCount, unwrappedMessages.Count);
            for (int i = 0; i < messagesCount; i++)
            {
                var serialized = MessageSerializer.SerializeMessage(messages[i]);
                Assert.AreEqual(serialized, unwrappedMessages[i]);
            }
        }