网上下的例子好想都这样的,比如:
private void StartListening()
{
//IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
IPAddress ipAddress = IPAddress.Parse("courageweb.gicp.net");
label1.Text = ipAddress.ToString();
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, listenport);
listener = new TcpListener(ipLocalEndPoint);
listener.Start();
while(true)
{
try
{
Socket s = listener.AcceptSocket();//接收一个套接字
clientsocket = s;//赋值给clientsocket
clientservice = new Thread(new ThreadStart(ServiceClient));//为新进client服务建立线程
clientservice.Start();//线程开始
}
catch (Exception e)//如果出现异常则打控制台打印到屏幕
{
Console.WriteLine(e.ToString());
}
}
}
HUWWW
慕侠2389804