Socket中是否存在如下机制:
           Server与Client已经建立Socket连接后,手动拔掉网线再插上,此Socket仍然有效,可以传送数据。
     如果没有此机制应该如何实现

解决方案 »

  1.   

    用线程判断,如果是断网即socket==null则重新new一下socket
      

  2.   

    断线重连机制:Socket重连是有限制的,
      

  3.   

    保存线程 断开后重新判断 如果socket通 则继续连接通信
      

  4.   

            //private void CheckConnection(object extra)
            //{
            //    if (client != null && client.Connected)
            //    {
            //        if (client.Poll(1, SelectMode.SelectRead))
            //        {
            //            try
            //            {
            //                client.Send(new byte[] { 0x12 });
            //                byte[] temp = new byte[1024];
            //                int nRead = client.Receive(temp);
            //                if (nRead == 0)
            //                {
            //                    MessageBox.Show("000连接已断开了,请处理");
            //                }
            //            }
            //            catch
            //            {
            //                MessageBox.Show("连接已断开了,请处理");
            //            }
            //        }
            //        try
            //        {
            //            string sendString = "IsConnection";        //        }
            //        catch (SocketException se)
            //        {
            //            if (se.ErrorCode == 10054) // Error code for Connection reset 
            //            {        //                MessageBox.Show("连接已断开了,请处理");
            //            }
            //            else
            //            {
            //                MessageBox.Show(se.Message);
            //            }
            //        }        //    }        //}
      

  5.   

    tcp连接在物理断开后会有重试机制,只要在重试超时内物理恢复后连接照样正常工作。