主题:请帮忙看看这个网络方面的问题(服务期监听)
private void button1_Click(object sender, EventArgs e)
{
try
{
IPAddress localaddr = Dns.GetHostAddresses(Dns.GetHostName())[0];//本机IP地址
// IPAddress localaddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];
TcpListener server = new TcpListener(localaddr, 5555);
server.Start();
client = server.AcceptTcpClient();/////////?????出错
MessageBox.Show("!!!!!!!!!");
while(true)
{
if (server.Pending()==false)
{
stream = client.GetStream();
th = new Thread(new ThreadStart(readdata));
th.Start();
}
}
}
catch (Exception ee)
{
MessageBox.Show("启动失败"+ee.Message);
}
}
//这是服务器的监听,但是运行到client = server.AcceptTcpClient()
就会出现卡死的情况(每次都是),就是窗口无法响应,为什么呢??
怎么改??谢谢了
{
try
{
IPAddress localaddr = Dns.GetHostAddresses(Dns.GetHostName())[0];//本机IP地址
// IPAddress localaddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];
TcpListener server = new TcpListener(localaddr, 5555);
server.Start();
client = server.AcceptTcpClient();/////////?????出错
MessageBox.Show("!!!!!!!!!");
while(true)
{
if (server.Pending()==false)
{
stream = client.GetStream();
th = new Thread(new ThreadStart(readdata));
th.Start();
}
}
}
catch (Exception ee)
{
MessageBox.Show("启动失败"+ee.Message);
}
}
//这是服务器的监听,但是运行到client = server.AcceptTcpClient()
就会出现卡死的情况(每次都是),就是窗口无法响应,为什么呢??
怎么改??谢谢了