Beispiel #1
0
        public static void OpenServer()
        {
            ip     = IPAddress.Parse("127.0.0.1");
            port   = 9999;
            server = new TcpListener(ip, port);

            TcpClient client = null;

            try
            {
                server.Start();
                Console.WriteLine("Server started!");
                while (true)
                {
                    Console.WriteLine("Waiting for a connection...");
                    client = server.AcceptTcpClient();//When execute this statement, perform a blocking call to accept requests.
                    clients.Add(client);
                    Console.WriteLine("Connected!");
                    ThreadFactory.StartThread(ThreadFactory.GetParameterizedThread(MaintainConnection), client);
                }
            }
            catch (Exception es)
            {
                Debug.WriteLine(es.ToString());
            }
            finally
            {
                Console.WriteLine("Server closed!");
            }
        }
Beispiel #2
0
 public TCPServer()
 {
     Console.WriteLine("Server starting...");
     ThreadFactory.StartThread(ThreadFactory.GetThread(OpenServer), null);
 }