Ejemplo n.º 1
0
        public void SendMessage(IMessage message)
        {
            var bytes = _dataConverter.GetBytes(message.Data);

            Console.WriteLine("SEND DATA TO <{0}>: {1}",
                              Handler.RemoteEndPoint, message.Data.Length < 1000
                ? message.Data.Replace(Environment.NewLine, string.Empty)
                : string.Format("{0} Lengths ", message.Data.Length));
            Console.WriteLine();
            var length = Handler.Send(bytes);

            OnSentMessage();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            try
            {
                while (!_ct.IsCancellationRequested)
                {
                    // timeout prevents deadlock if cancellation request is TRUE
                    _areSend.WaitOne(_waitTimeout);

                    TData item;
                    while (_queueSend.TryDequeue(out item))
                    {
                        //_logger.Info("SERVER Transmitting {0}", _queueSend.Peek());
                        _socket.Send(_converter.GetBytes(item));
                    }
                }

                _logger.Info("Send aborted by task");
            }
            catch (Exception ex)
            {
                _logger.Error("-------------------------------------------------");
                _logger.Error("Send Error");
                _logger.Error("-------------------------------------------------");
                _logger.Error(ex.Message + "\n" + ex.StackTrace);

                if (!_ct.IsCancellationRequested)
                {
                    OnError();
                }
            }
            _logger.Info("sending stopped!");
        }