Ejemplo n.º 1
0
        public async void StartAsync()
        {
            ThrowIfDisposed();
            _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            _listener.Bind(new IPEndPoint(GetLocalIpAddress(), _port));
            _listener.Listen(100);
            Console.WriteLine("Start listner with {0}:{1}", GetLocalIpAddress(), _port);
            IsRunning = true;
            while (IsRunning)
            {
                ThrowIfDisposed();
                var socket = await _listener.AcceptSocketAsync().ConfigureAwait(false);

                StartSocketAsync(socket);
                Console.WriteLine("Number of connections:{0}", Convert.ToInt32(_listSocket.Count));
            }
        }