回 帖 发 新 帖 刷新版面

主题:请帮忙看看这个网络方面的问题(服务期监听)

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()
就会出现卡死的情况(每次都是),就是窗口无法响应,为什么呢??
怎么改??谢谢了

回复列表 (共2个回复)

沙发



[img]http://bbs.supadmin.com/attachments/month_1002/10020922490b24c618b005c626.jpg[/img]

板凳



[img]http://bbs.supadmin.com/attachments/month_1002/10020922490b24c618b005c626.jpg[/img]

我来回复

您尚未登录,请登录后再回复。点此登录或注册