예제 #1
0
        public void Stop()
        {
            if (!_sendDataTask.IsRunning)
            {
                throw new Exception("The sender is not running.");
            }

            _sendDataTask.Stop();
            _sendDataTask.Dispose();

            _log.Info("Sending packets stopped.");
        }
예제 #2
0
        public void Run()
        {
            switch (_client.ipMode)
            {
            case IPMode.TCP:
                _tchannel = new TcpClient(_client.host, _client.port);
                Console.WriteLine("Client connected using TCP to {0}:{1}, rate {2} msg/s",
                                  _client.host,
                                  _client.port,
                                  _client.rate);
                _socket = _tchannel.Client;
                _socket.ReceiveBufferSize = 65536;
                _socket.SendBufferSize    = 65536 * 8;
                _socket.DontFragment      = false;
                _socket.NoDelay           = true;

                Console.WriteLine("SocketStatistics:");
                Console.WriteLine("\tDontFragment: {0}", _socket.DontFragment);
                Console.WriteLine("\tNoDelay: {0}", _socket.NoDelay);
                Console.WriteLine("\tReceiveBufferSize: {0}", _socket.ReceiveBufferSize);
                Console.WriteLine("\tReceiveTimeout: {0}", _socket.ReceiveTimeout);
                Console.WriteLine("\tSendBufferSize: {0}", _socket.SendBufferSize);
                Console.WriteLine("\tSendTimeout: {0}", _socket.SendTimeout);
                break;

            case IPMode.UDP:
                Console.WriteLine("Client sending using UDP to {0}:{1}, rate {2} msg/s",
                                  _client.host,
                                  _client.port,
                                  _client.rate);

                _uchannel = new UdpClient(_client.host, _client.port);
                _socket   = _uchannel.Client;
                _socket.ReceiveBufferSize = 65536 * 8;
                _socket.SendBufferSize    = 65536 * 8;
                _socket.DontFragment      = false;

                Console.WriteLine("SocketStatistics:");
                Console.WriteLine("\tDontFragment: {0}", _socket.DontFragment);
                Console.WriteLine("\tReceiveBufferSize: {0}", _socket.ReceiveBufferSize);
                Console.WriteLine("\tReceiveTimeout: {0}", _socket.ReceiveTimeout);
                Console.WriteLine("\tSendBufferSize: {0}", _socket.SendBufferSize);
                Console.WriteLine("\tSendTimeout: {0}", _socket.SendTimeout);
                break;
            }

            _eventPer50Ms       = _client.rate / 20;
            _tickerIndex        = 0;
            _countLast5S        = 0;
            _sleepLast5S        = 0;
            _lastThroughputTick = Environment.TickCount;
            _eventCount         = 0;
            _maxEventCount      = _client.totalEvents;

            try
            {
                var highPerformanceTimer = new HighResolutionTimer(
                    HandleTimerEvents,
                    null,
                    0,
                    50);

                Console.WriteLine(">> Press Any Key To Exit <<");
                Console.ReadKey();

                highPerformanceTimer.Dispose();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error sending data to server.  Did server disconnect");
                Console.Error.WriteLine("Error message: {0}", e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
        }