HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-05-21 98ceb6bd2021f9ff136cda27eef28676dd7b5d92
ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
@@ -334,10 +334,6 @@
        {
            //本地Socket
            public static Socket busSocket;
            /// <summary>
            /// 计时器
            /// </summary>
            private static int timeCount = 0;
            /// <summary>
            /// 启动Socket接收和发送功能
@@ -395,52 +391,10 @@
            {
                try
                {
                    //检测连接状态
                    CheckConnectiton();
                    Start(7624);
                    busSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, iPEndPoint, new AsyncCallback(asyncEndSend), null);
                }
                catch { }
            }
            /// <summary>
            /// 检测连接状态
            /// </summary>
            private static void CheckConnectiton()
            {
                if (busSocket == null) { return; }
                timeCount++;
                if (timeCount < 20)
                {
                    //每10秒检测一次
                    return;
                }
                timeCount = 0;
                bool blockingState = busSocket.Blocking;
                try
                {
                    byte[] tmp = new byte[1];
                    busSocket.Blocking = false;
                    busSocket.Send(tmp, 0, 0);
                    //tcp还在连接着
                    busSocket.Blocking = blockingState;
                }
                catch (SocketException e)
                {
                    // 10035 == WSAEWOULDBLOCK
                    if (e.NativeErrorCode.Equals(10035))
                    {
                        //Still Connected, but the Send would block
                    }
                    else
                    {
                        //tcp已经断开了连接
                        Stop();
                    }
                }
            }
            /// <summary>