/// <summary>
        /// Start accepting connections.
        /// </summary>
        public void Start()
        {
            if (_IsListening)
            {
                throw new InvalidOperationException("SimpleTcpServer is already running.");
            }

            _Listener = new TcpListener(_IPAddress, _Port);

            _Listener.Start();
            _IsListening = true;

            _TokenSource       = new CancellationTokenSource();
            _Token             = _TokenSource.Token;
            _Statistics        = new SimpleTcpStatistics();
            _IdleClientMonitor = Task.Run(() => IdleClientMonitor(), _Token);
            _AcceptConnections = Task.Run(() => AcceptConnections(), _Token);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Start accepting connections.
        /// </summary>
        /// <returns>Task.</returns>
        public Task StartAsync()
        {
            if (_IsListening)
            {
                throw new InvalidOperationException("SimpleTcpServer is already running.");
            }

            _Listener = new TcpListener(_IPAddress, _Port);

            if (_Keepalive.EnableTcpKeepAlives)
            {
                EnableKeepalives();
            }

            _Listener.Start();
            _TokenSource = new CancellationTokenSource();
            _Token       = _TokenSource.Token;
            _Statistics  = new SimpleTcpStatistics();
            return(AcceptConnections()); // sets _IsListening
        }
Exemplo n.º 3
0
        /// <summary>
        /// Start accepting connections.
        /// </summary>
        /// <returns>Task.</returns>
        public Task StartAsync()
        {
            if (_IsListening)
            {
                throw new InvalidOperationException("SimpleTcpServer is already running.");
            }

            _Listener = new TcpListener(_IPAddress, _Port);

            if (_Keepalive.EnableTcpKeepAlives)
            {
                EnableKeepalives();
            }

            _TokenSource       = new CancellationTokenSource();
            _Token             = _TokenSource.Token;
            _Statistics        = new SimpleTcpStatistics();
            _IdleClientMonitor = Task.Run(() => IdleClientMonitor(), _Token);
            _AcceptConnections = Task.Run(() => AcceptConnections(), _Token);
            return(_AcceptConnections);
        }