HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-05-15 3f87bf0ae7394cdd7d52428f1f6b4361434c7cc4
ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs
@@ -333,7 +333,7 @@
        public static class FindGateWaySocket
        {
            //本地Socket
            public static System.Net.Sockets.Socket busSocket;
            public static Socket busSocket;
            /// <summary>
            /// 启动Socket接收和发送功能
@@ -379,7 +379,7 @@
            {
                get
                {
                    return null == busSocket ? false : true;
                    return busSocket == null ? false : true;
                }
            }
@@ -391,12 +391,47 @@
            {
                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; }
                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>