Пример #1
0
 public void Start()
 {
     try
     {
         TcpListener server = new TcpListener(local, port);
         Console.WriteLine("准备启动服务器...");
         Console.WriteLine("本机IP:" + local.ToString() + " 监听端口号:" + port);
         server.Start();
         Console.WriteLine("服务器启动...");
         while (true)
         {
             Socket socket = server.AcceptSocket();
             Console.WriteLine("收到一个连接...");
             MyServerConnection conn = new MyServerConnection(socket);
             Thread             thd  = new Thread(new ThreadStart(conn.run));
             thd.Start();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("W_W:" + e.ToString());
         return;
     }
 }
Пример #2
0
 public void Start()
 {
     try
     {
         TcpListener server = new TcpListener(local, port);
         Console.WriteLine("准备启动服务器...");
         Console.WriteLine("本机IP:" + local.ToString() + " 监听端口号:" + port);
         server.Start();
         Console.WriteLine("服务器启动...");
         while (true)
         {
             Socket socket = server.AcceptSocket();
             Console.WriteLine("收到一个连接...");
             MyServerConnection conn = new MyServerConnection(socket);
             Thread thd = new Thread(new ThreadStart(conn.run));
             thd.Start();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("W_W:" + e.ToString());
         return;
     }
 }