Beispiel #1
0
        /// <summary>
        /// Listens for clients.
        /// </summary>
        private void Listen()
        {
            ConsoleLogger.WriteToLog("Listening at Port: " + Port);

            while (IsRunning)
            {
                TcpClientConnected.Reset();

                ConsoleLogger.WriteToLog("Waiting for Client Connections...");

                Server.BeginAcceptTcpClient(new AsyncCallback(EventTcpClientAccept), Server);

                TcpClientConnected.WaitOne();

                if (!IsRunning)
                {
                    break;
                }
            }

            ConsoleLogger.WriteToLog("Stopped Listening for Clients.");
        }
Beispiel #2
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start(IPAddress listenAddress)
        {
            ConsoleLogger.WriteToLog("Starting Server...", true);

            while (!IsRunning)
            {
                try
                {
                    Server = new TcpListener(listenAddress, Port);
                    Server.Start();
                    IsRunning = true;
                }
                catch (SocketException)
                {
                    Port++;
                }
            }

            ListenThread = new Thread(Listen);
            ListenThread.IsBackground = true;
            ListenThread.Start();

            ConsoleLogger.WriteToLog("Server successfully Started...", true);

            TcpClientConnected.WaitOne(200);

            Thread console = new Thread(new ThreadStart(RunConsoleMenu));

            console.IsBackground = true;
            console.Start();

            Thread title = new Thread(new ThreadStart(UpdateTitle));

            title.IsBackground = true;
            title.Start();
        }