Exemplo n.º 1
0
        /// <summary>
        /// Writes data to the current connection.
        /// </summary>
        /// <param name="msg">Message to send</param>
        public void Write(string msg)
        {
            if (!Connected)
            {
                return;
            }
            Logger.DebugFormat(this, "Outgoing Message: {0}", msg);
            var mesg = _utf.GetBytes(msg);

            mesg = _compressed ? _comp.Deflate(mesg) : mesg;
            _stream.Write(mesg, 0, mesg.Length);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Writes data to the current connection.
        /// </summary>
        /// <param name="msg">Message to send</param>
        public void Write(string msg)
        {
            Log.Debug("Outgoing message: {Message}", msg);

            if (!Connected)
            {
                return;
            }
            byte[] mesg = _utf.GetBytes(msg);
            mesg = _compressed ? _compression.Deflate(mesg) : mesg;
            _stream.Write(mesg, 0, mesg.Length);
        }
Exemplo n.º 3
0
        private void SocketSend(string message, bool synchronized = false)
        {
            if (!IsConnected || string.IsNullOrEmpty(message))
            {
                return;
            }

            // Prepare message
            _socketWriteMessage = message;
            byte[] writeBytes = _encoding.GetBytes(message);
            if (_isCompressionEnabled)
            {
                writeBytes = _compression.Deflate(writeBytes);
            }

            IBuffer sendBuffer = CryptographicBuffer.CreateFromByteArray(writeBytes);

            if (synchronized)
            {
                // Wait for completion
                _elevateMutex.WaitOne(4000);
                _socket.OutputStream.WriteAsync(sendBuffer).AsTask().Wait(4000);
            }
            else
            {
                // wait for last task and start new one
                // Wait for other reads to finish
                if (_socketWriter != null && _socketWriter.Status == AsyncStatus.Started)
                {
                    try
                    {
                        _socketWriter.AsTask().Wait(4000);
                    }
                    catch
                    {
                        // if (_socketWriter.Status == AsyncStatus.Started)
                        // {
                        // ConnectionError(ErrorType.WriteStateMismatch, ErrorPolicyType.Reconnect);
                        // return;
                        // }
                    }
                }

                _elevateMutex.WaitOne(4000);

                if (IsConnected)
                {
                    _socketWriter           = _socket.OutputStream.WriteAsync(sendBuffer);
                    _socketWriter.Completed = OnSocketWriterCompleted;
                }
            }
        }