xm
2020-05-19 136b9e2fc48249a5ff89874f1080ba94130e7a9e
ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
@@ -333,7 +333,11 @@
        public static class FindGateWaySocket
        {
            //本地Socket
            public static System.Net.Sockets.Socket busSocket;
            public static Socket busSocket;
            /// <summary>
            /// 计时器
            /// </summary>
            private static int timeCount = 0;
            /// <summary>
            /// 启动Socket接收和发送功能
@@ -379,7 +383,7 @@
            {
                get
                {
                    return null == busSocket ? false : true;
                    return busSocket == null ? false : true;
                }
            }
@@ -391,12 +395,54 @@
            {
                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>
            /// 异步发送数据结束
            /// </summary>