本帖最后由 guo329838627 于 2013-9-27 14:52 编辑
每当关闭socket [socket.close();]时,就提示异常“一个封锁操作被对 WSACancelBlockingCall 的调用中断!”请问各位大侠这是神马原因?
源代码: //创建一个SOcket- Socket socket=null;
- Thread thread = null;
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
- IPAddress ipAddress = IPAddress.Parse(ip.Text.Trim());
- IPEndPoint ipEndPoint = new IPEndPoint(ipAddress,int.Parse(duankou.Text));
- socket.Bind(ipEndPoint);
- socket.Listen(10);
- thread = new Thread(Lianjie);
- thread.IsBackground = true;
- thread.Start();
- }
- 、 catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
复制代码 //监听客户端的方法- public void Lianjie()
- {
- while (true)
- {
- try
- {
- Socket socketconnection = socket.Accept();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- break;
- }
- }
- }
复制代码 |