Пример #1
0
 public void SENDPING()
 {
     while (true)
     {
         if (_SEND_REQSCAN_On)
         {
             for (; _times_Send_REQSCAN < _times_Total_REQSCAN;)
             {
                 if (_scm._isConnected)
                 {
                     _scm.SendMsg(PackingSocketMsg("LON"));
                     AppendSendText("BARCODE(" + (++_times_Send_REQSCAN).ToString() + "/" + _times_Total_REQSCAN.ToString() + "):LON_Send");
                 }
                 else
                 {
                     _times_Send_REQSCAN = _times_Total_REQSCAN;
                 }
                 if (_times_Send_REQSCAN < _times_Total_REQSCAN)
                 {
                     Thread.Sleep(_timer_REQSCAN);
                 }
             }
             _SEND_REQSCAN_On = false;
         }
         else
         {
             _Event_SEND_REQSCAN.WaitOne();
         }
     }
 }
Пример #2
0
 public void SENDPING()
 {
     while (true)
     {
         if (_SEND_PING_On)
         {
             for (; _times_Send_PING < _times_Total_PING;)
             {
                 _times_Send_PING++;
                 if (_scm._isConnected)
                 {
                     _scm.SendMsg(PackingSocketMsg("PING_REQ"));
                     AppendSendText("PING_REQ(" + _times_Send_PING.ToString() + "/" + _times_Total_PING.ToString() + "):Send");
                 }
                 else
                 {
                     _times_Send_PING = _times_Total_PING;
                 }
                 if (_times_Send_PING < _times_Total_PING)
                 {
                     Thread.Sleep(_timer_PING);
                 }
             }
             _SEND_PING_On = false;
         }
         else
         {
             _Event_SEND_PING.WaitOne();
         }
     }
 }
Пример #3
0
        private void PINGSocketThread()
        {
            while (true)
            {
                try
                {
                    if (_childThreadPING_isOn)
                    {
                        if (_scm != null && _scm._isConnected)
                        {
                            //判断发送PING Request
                            //没发PING没接收PING    或    发送PING接收PING
                            if ((!_PING_Send && !_PING_Received) || (_PING_Send && _PING_Received))
                            {
                                _PING_Send     = true;
                                _PING_Received = false;
                                _socketReset   = false;
                                _scm.SendMsg(PackingSocketMsg("PING_REQ"));
                                AppendToListView("Socket " + _msgClass4Log + " <<Send : PING_REQ", CONVERTOR, MES, "OK");

                                _PING_RetryTimes = 0;
                            }
                            else
                            {
                                //没法PING 并且 接收PING
                                if (!_PING_Send && _PING_Received)
                                {
                                    _PING_Send            = false;
                                    _PING_Received        = false;
                                    _socketReset          = true;
                                    _childThreadPING_isOn = false;
                                }
                                //发送送没收到
                                else if (_PING_Send && !_PING_Received)
                                {
                                    //重发的次数小于三次
                                    if (_PING_RetryTimes < _PingRetryCount)
                                    {
                                        _PING_Send     = true;
                                        _PING_Received = false;
                                        AppendToListView("Socket " + _msgClass4Log + " : PING is no repsonse,Try " + (++_PING_RetryTimes).ToString() + " times : " + _ip + ":" + _port.ToString()
                                                         + " : Will Try Send PING in " + (_timer / 1000).ToString() + " s !", "SOCKETBASE", ERROR, "NG");
                                        _scm.SendMsg(PackingSocketMsg("PING_REQ"));
                                        //AppendToListView("Socket " + _msgClass4Log + " : PING_REQ : " + _PING_RetryTimes.ToString() + "/" + _PingRetryCount.ToString(), CONVERTOR, MES,"OK");
                                    }
                                    //三次失败,自己去睡觉
                                    else if (_PING_RetryTimes >= _PingRetryCount)
                                    {
                                        _PING_Send       = false;
                                        _PING_Received   = false;
                                        _PING_RetryTimes = 0;
                                        AppendToListView("Socket " + _msgClass4Log + " : Channel will be reset since Ping is no repsonse 3 times : " + _ip + ":" + _port.ToString()
                                                         , "SOCKETBASE", ERROR, "NG");

                                        //自己睡觉,告诉主线程停止循环自己
                                        _socketReset          = true;
                                        _childThreadPING_isOn = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            _PING_Send            = false;
                            _PING_Received        = false;
                            _socketReset          = false;
                            _childThreadPING_isOn = false;
                        }
                    }
                    else
                    {
                        _PING_Send     = false;
                        _PING_Received = false;
                        //等待主人(线程)叫起床
                        _childThreadPING_ResetEvent.WaitOne();
                    }
                }
                catch
                {
                    AppendToListView("Socket " + _msgClass4Log + " : SOCKETBASE_0006", "SOCKETBASE", ERROR, "NG");
                }
                Thread.Sleep(_timer);
            }
        }