Ejemplo n.º 1
0
        /// <summary>
        /// Enqueues message to send
        /// </summary>
        /// <param name="message">The message to send</param>
        /// <param name="exact">Can be used to prevent compression</param>
        /// <param name="immediate">If true, the message is sent unformatted and immediately</param>
        public virtual ulong Send(byte[] message, bool exact, bool immediate)
        {
            if (!IsConnected || message == null)
            {
                return(0);
            }
            var size = message.Length;

            if (!exact && UseCompression)
            {
                message = message.AsCompressed();
            }
            //if (System.Diagnostics.Debugger.IsAttached)
            //Console.WriteLine("UseCompression = {0}: Original Size = {1}, Actual Size = {2}", UseCompression, size, message.Length);
            System.Diagnostics.Debug.WriteLine("UseCompression = {0}: Original Size = {1}, Actual Size = {2}", UseCompression, size, message.Length);
            _messageCount += 1;
            if (immediate)
            {
                W.Net.StreamHelpers.SendMessageAsync(_networkStream, _client.SendBufferSize, message);
            }
            else
            {
                _writer.Send(new SocketData()
                {
                    Id = _messageCount, Data = message
                });
            }
            return(_messageCount);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Enqueues message to send
 /// </summary>
 /// <param name="message">The message to send</param>
 /// <param name="immediate">If true, the message is sent unformatted and immediately</param>
 public virtual void Send(byte[] message, bool immediate = false)
 {
     if (!IsConnected || message == null)
     {
         return;
     }
     if (UseCompression)
     {
         var size = message.Length;
         message = message.AsCompressed();
         Log.v("Original Size = {0}, Compressed Size = {1}", size, message.Length);
     }
     if (immediate)
     {
         W.Net.TcpHelpers.SendMessageAsync(_networkStream, _client.SendBufferSize, message);
     }
     else
     {
         _writer.Send(message);
     }
 }