Пример #1
0
        private void StartListening()
        {
            IPHostEntry ipHostEntry   = Dns.GetHostEntry(host);
            IPAddress   ipAddress     = ipHostEntry.AddressList[0];
            IPEndPoint  localEndPoint = new IPEndPoint(ipAddress, port);

            listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                WriteLog(LogStrings.TryingToBindListenerToEndPoint(localEndPoint));
                listener.Bind(localEndPoint);
                WriteLog(LogStrings.BindingWasSuccessful(localEndPoint));
                listener.Listen(maxNumberOfListeners);
                WriteLog(LogStrings.StartingToListenConnections());
            } catch (Exception exc)
            {
                WriteLog(LogStrings.ExceptionWasThrown(exc));
            }
        }