Ping() public static method

public static Ping ( string server ) : string
server string
return string
コード例 #1
0
            private void _Worker()
            {
#if LOG4NET
                Logger.Socket.Debug("IdleWorkerThread started");
#endif
                try {
                    while (_Connection.IsConnected)
                    {
                        if (_Connection.IsRegistered)
                        {
                            DateTime now            = DateTime.Now;
                            int      last_ping_sent = (int)(now - _Connection._LastPingSent).TotalSeconds;
                            int      last_pong_rcvd = (int)(now - _Connection._LastPongReceived).TotalSeconds;
                            // determins if the resoponse time is ok
                            if (last_ping_sent < _Connection._PingTimeout)
                            {
                                // determines if it need to send another ping yet
                                if (last_pong_rcvd > _Connection._PingInterval)
                                {
                                    _Connection.WriteLine(Rfc2812.Ping(_Connection.Address), Priority.Critical);
                                    _Connection._LastPingSent     = now;
                                    _Connection._LastPongReceived = now;
                                } // else connection is fine, just continue
                            }
                            else
                            {
#if LOG4NET
                                Logger.Socket.Warn("ping timeout, connection lost");
#endif
                                _Connection.IsConnectionError = true;
                                break;
                            }
                        }
                        Thread.Sleep(_Connection._IdleWorkerInterval);
                    }
                } catch (ThreadAbortException) {
                    Thread.ResetAbort();
#if LOG4NET
                    Logger.Socket.Debug("IdleWorkerThread aborted");
#endif
                }
            }
コード例 #2
0
ファイル: IrcConnection.cs プロジェクト: zerk-js/SOTSII-SOS
 private void _Worker()
 {
     try
     {
         while (this._Connection.IsConnected)
         {
             Thread.Sleep(this._Connection._IdleWorkerInterval);
             if (this._Connection.IsRegistered)
             {
                 DateTime now           = DateTime.Now;
                 int      totalSeconds1 = (int)(now - this._Connection._LastPingSent).TotalSeconds;
                 int      totalSeconds2 = (int)(now - this._Connection._LastPongReceived).TotalSeconds;
                 if (totalSeconds1 < this._Connection._PingTimeout)
                 {
                     if (!(this._Connection._LastPingSent > this._Connection._LastPongReceived) && totalSeconds2 > this._Connection._PingInterval)
                     {
                         this._Connection.WriteLine(Rfc2812.Ping(this._Connection.Address), Priority.Critical);
                         this._Connection._LastPingSent = now;
                     }
                 }
                 else
                 {
                     if (this._Connection.IsDisconnecting)
                     {
                         break;
                     }
                     this._Connection.IsConnectionError = true;
                     break;
                 }
             }
         }
     }
     catch (ThreadAbortException ex)
     {
         Thread.ResetAbort();
     }
     catch (Exception ex)
     {
     }
 }
コード例 #3
0
ファイル: IrcConnection.cs プロジェクト: mBr001/CSharpIRCBot
            private void _Worker()
            {
#if LOG4NET
                Logger.Socket.Debug("IdleWorkerThread started");
#endif
                try {
                    while (_Connection.IsConnected)
                    {
                        Thread.Sleep(_Connection._IdleWorkerInterval);

                        // only send active pings if we are registered
                        if (!_Connection.IsRegistered)
                        {
                            continue;
                        }

                        DateTime now            = DateTime.Now;
                        int      last_ping_sent = (int)(now - _Connection._LastPingSent).TotalSeconds;
                        int      last_pong_rcvd = (int)(now - _Connection._LastPongReceived).TotalSeconds;
                        // determins if the resoponse time is ok
                        if (last_ping_sent < _Connection._PingTimeout)
                        {
                            if (_Connection._LastPingSent > _Connection._LastPongReceived)
                            {
                                // there is a pending ping request, we have to wait
                                continue;
                            }

                            // determines if it need to send another ping yet
                            if (last_pong_rcvd > _Connection._PingInterval)
                            {
                                _Connection.WriteLine(Rfc2812.Ping(_Connection.Address), Priority.Critical);
                                _Connection._LastPingSent = now;
                                //_Connection._LastPongReceived = now;
                            } // else connection is fine, just continue
                        }
                        else
                        {
                            if (_Connection.IsDisconnecting)
                            {
                                break;
                            }
#if LOG4NET
                            Logger.Socket.Warn("ping timeout, connection lost");
#endif
                            // only flag this as connection error if we are not
                            // cleanly disconnecting
                            _Connection.IsConnectionError = true;
                            break;
                        }
                    }
                } catch (ThreadAbortException) {
                    Thread.ResetAbort();
#if LOG4NET
                    Logger.Socket.Debug("IdleWorkerThread aborted");
#endif
                } catch (Exception ex) {
#if LOG4NET
                    Logger.Socket.Error(ex);
#endif
                }
            }
コード例 #4
0
 public void RfcPing(string server, string server2) => WriteLine(Rfc2812.Ping(server, server2));
コード例 #5
0
 public void RfcPing(string server, string server2, Priority priority) => WriteLine(Rfc2812.Ping(server, server2), priority);
コード例 #6
0
ファイル: IrcCommands.cs プロジェクト: zerk-js/SOTSII-SOS
 public void RfcPing(string server)
 {
     this.WriteLine(Rfc2812.Ping(server));
 }
コード例 #7
0
ファイル: IrcCommands.cs プロジェクト: zerk-js/SOTSII-SOS
 public void RfcPing(string server, Priority priority)
 {
     this.WriteLine(Rfc2812.Ping(server), priority);
 }