Try Follow:
public MyListener2()
{
try
{
listener = new TcpListener(portNum);
listener.Start();
                            Integer i;
                            Integer ConnNumber=10;
                            for(i=0;i<ConnNumber;i++)
                            {
Thread th = new Thread(new ThreadStart(StartListen));
th.Start();
                            }
}
catch(Exception e)
{
Console.WriteLine("监听端口错误,信息:"+e.ToString());
}
}

解决方案 »

  1.   

    这样是可以,但是这样限制得很死,最多只能让十个client同时连上来。而且一开始就开十个线程,浪费系统资源嘛。我想要实现的功能是每当有一个client连上来时就开多一个线程,但不知道怎样实现。
      

  2.   

    IPAddress hostadd = Dns.Resolve(server).AddressList[0];
      IPEndPoint EPhost = new IPEndPoint(hostadd, 80);
      //Creates the Socket for sending data over TCP.
      Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
         ProtocolType.Tcp );
     try {
        aSocket.Bind(EPhost);
    }
    catch (Exception e) {
        Console.WriteLine("Winsock error: " + e.ToString());
    }
     
    // Allows a queue of 10 connections.
    aSocket.Listen(10);
    if (!aSocket.Connected) {
       Console.WriteLine("Winsock error: "
          + Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()));
      

  3.   

    http://www.codeproject.com/dotnet/DotNetTCP.asp
      

  4.   

    开一个监视线程,监视CLIENT的连接请求,PRIORITY设为HIGHEST.每发现一个请求就启动一个通讯线程,用于连接.
      

  5.   

    我解决了,应该是在TcpClient client = listener.AcceptTcpClient();这句后开多线程,YEAH.