Example #1
0
        private void SendMessage(INetworkMessage message, bool useEncryption, bool managementProtocol = false)
        {
            if (useEncryption)
            {
                message.PrepareToSend(this.XTeaKey);
            }
            else
            {
                message.PrepareToSendWithoutEncryption(managementProtocol);
            }

            try
            {
                lock (this.writeLock)
                {
                    this.stream.BeginWrite(message.Buffer, 0, message.Length, null, null);
                }
            }
            catch (ObjectDisposedException)
            {
                this.Close();
            }
        }