Esempio n. 1
0
        // Blocker call
        public void Listen()
        {
            this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                this._socket.Bind(this._localEndPoint);
                this._socket.Listen(100);
                _logger.Info($"TCP port listening on: {this._localEndPoint}");

                while (true)
                {
                    _connAccepted.Reset();
                    this._socket.BeginAccept(new AsyncCallback(AcceptHandler), this._socket);
                    _connAccepted.WaitOne();
                }
            }
            catch (Exception e) {
                _logger.Fatal("Server socket error: " + e.ToString());
            }
        }