void EventSource_OnPingReq(object sender, PingEventArgs e) { if (Client is RemoteClient) { Client.SendPingResp(e.Value); } }
private static void Con_PingEvent(object sender, PingEventArgs e) { if (isConnected) { Console.WriteLine("Ping is " + e.PingReply.RoundtripTime + " ms"); } }
/// <summary> /// A k-bucket is full! /// </summary> /// <remarks> /// Currently this just removes the oldest contact from the list, /// without acutally pinging the individual peers. /// /// This is the same as go does, but should probably /// be upgraded to actually ping the individual peers. /// </remarks> private void Peers_Ping(object sender, PingEventArgs <RoutingPeer> e) { if (_peers.Remove(e.Oldest.First())) { _peers.Add(e.Newest); } }
internal void HandleOnPing(object sender, PingEventArgs e) { if (OnPing != null) { OnPing(this, e); } }
void EventSource_OnPingResp(object sender, PingEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { txtPing.Text = string.Format("{0}ms", e.Value); })); }
protected virtual void OnPingRequest(PingEventArgs e) { EventHandler <PingEventArgs> handler = PingRequest; if (handler != null) { handler(this, e); } }
public static bool OnPing(object sender, PingEventArgs e) { _ping = true; ++_pingCount; return(true); }
private void OnPing(object sender, PingEventArgs e) { Console.WriteLine("Responded to ping at {0}.", DateTime.Now.ToShortTimeString()); }
private void FrameBuilder_OnPing(object sender, PingEventArgs e) { base.OnPing(e.Payload); }
public bool WhatClubDoYouUsePingAhGood (object sender, PingEventArgs e) { _ping = true; return true; }
public void PluginsOnPing(object sender, PingEventArgs e) { OnPing(this, e); }
/// <summary> /// Called when [pong]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="T:PWebSocketServer.Common.Events.PingEventArgs" /> instance containing the event data.</param> public virtual void OnPong(IWebSocketConnection sender, PingEventArgs args) { }
private bool OnPing (object sender, PingEventArgs e) { _ping = true; ++_pingCount; return true; }
private bool OnPing(object sender, PingEventArgs e) { _ping = true; ++_pingCount; return(true); }
//Handlers chargé d'effectuer une action à chaque fois que twitch vérifie que nous sommes bien connectés void OnPing(object sender, PingEventArgs e) { SendAdminMessage("Responded to ping at {0}." + DateTime.Now.ToShortTimeString()); }
private void Handler_OnPing(object sender, PingEventArgs pingdata) { //m_Handler.P//throw new NotImplementedException(); }
void EventSource_OnPingReq(object sender, PingEventArgs e) { if (Client is RemoteClient) Client.SendPingResp(e.Value); }
public void StartPing(object argument) { if (IsOffline()) return; IPAddress ip = (IPAddress)argument; //set options ttl=128 and no fragmentation PingOptions options = new PingOptions(128, true); //create a Ping object Ping ping = new Ping(); //32 empty bytes buffer byte[] data = new byte[32]; int received = 0; List<long> responseTimes = new List<long>(); string resp = string.Empty; //ping 4 times for (int i = 0; i < 4; i++) { PingReply reply = ping.Send(ip, 1000, data, options); if (reply != null) { switch (reply.Status) { case IPStatus.Success: resp = "Reply from " + reply.Address + ": bytes=" + reply.Buffer.Length + " time=" + reply.RoundtripTime + "ms TTL=" + reply.Options.Ttl; PingEventArgs pe = new PingEventArgs(resp); Change(this, pe); received++; responseTimes.Add(reply.RoundtripTime); break; case IPStatus.TimedOut: pe = new PingEventArgs("Request timed out."); Change(this, pe); break; default: pe = new PingEventArgs("Ping failed " + reply.Status.ToString()); Change(this, pe); break; } } else { PingEventArgs pe = new PingEventArgs("Ping failed for an unknown reason"); Change(this, pe); } reply = null; } ping.Dispose(); //statistics calculations long averageTime = -1; long minimumTime = 0; long maximumTime = 0; for (int i = 0; i < responseTimes.Count; i++) { if (i == 0) { minimumTime = responseTimes[i]; maximumTime = responseTimes[i]; } else { if (responseTimes[i] > maximumTime) { maximumTime = responseTimes[i]; } if (responseTimes[i] < minimumTime) { minimumTime = responseTimes[i]; } } averageTime += responseTimes[i]; } StringBuilder statistics = new StringBuilder(); statistics.AppendLine(); statistics.AppendLine(); statistics.AppendFormat("Ping statistics for {0}:", ip.ToString()); statistics.AppendLine(); statistics.AppendFormat(" Packets: Sent = 4, " + "Received = {0}, Lost = {1} <{2}% loss>,", received, 4 - received, Convert.ToInt32(((4 - received) * 100) / 4)); statistics.AppendLine(); statistics.AppendLine(); //show only if loss is not 100% if (averageTime != -1) { statistics.Append("Approximate round trip times in milli-seconds:"); statistics.AppendLine(); statistics.AppendFormat(" Minimum = {0}ms, " + "Maximum = {1}ms, Average = {2}ms", minimumTime, maximumTime, (long)(averageTime / received)); } PingEventArgs pes = new PingEventArgs(statistics.ToString()); Change(this, pes); }
public void OnPingUpdate(object sender, PingEventArgs latest) { RobotState.SetPingDistance(latest.Distance); }
private async void ReceiverLoop(object obj) { WebSocketReceiveResult r; var buffer = new byte[ReceiveChunkSize]; var bufferSegment = new ArraySegment <byte>(buffer); pingRequestDeadline = Environment.TickCount + (int)PingInterval.TotalMilliseconds; pongTimeoutDeadline = Environment.TickCount + (int)PingTimeout.TotalMilliseconds; Task <WebSocketReceiveResult> tReceive = null; Task tPing = null; while (_socket.State == WebSocketState.Open) { try { if (tReceive == null) { tReceive = _socket.ReceiveAsync(bufferSegment, CancellationToken.None); } } catch (ObjectDisposedException) { break; } if (tPing == null) { tPing = Task.Delay(Math.Max(0, Math.Min(pingRequestDeadline - Environment.TickCount, pongTimeoutDeadline - Environment.TickCount))); } var t = await Task.WhenAny(tReceive, tPing); if (t == tReceive) { try { r = await tReceive; tReceive = null; } catch (WebSocketException) { // Disconnection? break; } switch (r.MessageType) { case WebSocketMessageType.Text: if (r.Count > 0) { // Defalut engine.io protocol switch (buffer[0]) { case (byte)'3': // Server Pong pongTimeoutDeadline = Environment.TickCount + (int)PingTimeout.TotalMilliseconds; PingEventArgs pingArgs = new PingEventArgs(pingRequestAt, Environment.TickCount); OnPing?.Invoke(pingArgs); break; case (byte)'4': // Message if (r.Count > 1) { // Defalut socket.io protocol switch (buffer[1]) { // Ignore All of them. it's just for understanding ! case (byte)'0': // Connect case (byte)'1': // Disconnect // Ignored break; case (byte)'2': // Event case (byte)'3': // Ack case (byte)'4': // Error case (byte)'5': // Binary_Event case (byte)'6': // Binary_Ack // Ignored break; } } // Listen to message var builder = new StringBuilder(); string str = Encoding.UTF8.GetString(buffer, 0, r.Count); builder.Append(str); while (!r.EndOfMessage) { r = await _socket.ReceiveAsync(new ArraySegment <byte>(buffer), _tokenSource.Token); str = Encoding.UTF8.GetString(buffer, 0, r.Count); builder.Append(str); } var parser = new ResponseTextParser(_namespace, this) { Text = builder.ToString() }; await parser.ParseAsync(); break; } } break; case WebSocketMessageType.Binary: case WebSocketMessageType.Close: default: // Nothing to handle break; } } else { if (Environment.TickCount - pingRequestDeadline >= 0) { if (Interlocked.CompareExchange(ref pingRequest, 1, 0) == 0) { pingRequest = 1; WakeSenderLoop(); pingRequestDeadline = Environment.TickCount + (int)PingInterval.TotalMilliseconds; pongTimeoutDeadline = Environment.TickCount + (int)PingTimeout.TotalMilliseconds; } } if (Environment.TickCount - pongTimeoutDeadline >= 0) { // Ping timeout try { await _socket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "Ping timeout", CancellationToken.None); } catch (WebSocketException) { } catch (ObjectDisposedException) { } break; } } } serverCloseReason = ServerCloseReason.SocketAborted; await CloseAsync(); }
protected virtual void OnPing(PingEventArgs e) { CanPong = true; }
private bool IsOffline() { ConnectionState flags = 0; InternetGetConnectedState(ref flags, 0); //bool isConnected = InternetGetConnectedState(ref flags, 0); //bool isConfigured = (flags & ConnectionState.INTERNET_CONNECTION_CONFIGURED) != 0; //bool isOffline = (flags & ConnectionState.INTERNET_CONNECTION_OFFLINE) != 0; //bool isConnectedUsingModem = (flags & ConnectionState.INTERNET_CONNECTION_MODEM) != 0; //bool isConnectedUsingLAN = (flags & ConnectionState.INTERNET_CONNECTION_LAN) != 0; //bool isProxyUsed = (flags & ConnectionState.INTERNET_CONNECTION_PROXY) != 0; //bool isRasEnabled = (flags & ConnectionState.INTERNET_RAS_INSTALLED) != 0; if (((int)ConnectionState.INTERNET_CONNECTION_OFFLINE & (int)flags) != 0) { PingEventArgs pes = new PingEventArgs("No internet connection detected."); Change(this, pes); return true; } return false; }
void EventSource_OnPingResp(object sender, PingEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { txtPing.Text = string.Format("{0}ms", e.Value); })); }
private void WebsocketPacketHandler_SocketMessageReceived(List <Packet> packets) { // Server may send more than one packet. // ------------------------------------- foreach (var packet in packets) { if (packet.Header == ConnectionAcceptedPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } SendPacket(new ClientInfoPacket(false, UserAgent, packet.Data["hash"].ToString(), 0, false)); SendPacket(new OpenAcknowledgedPacket()); var eventArgs = new ConnectionAcceptedEventArgs(packet.Data["conn_id"].ToString(), packet.Data["hash"].ToString()); ConnectionAccepted?.Invoke(this, eventArgs); continue; } if (packet.Header == ConversationEndedPacket.ToString()) { // Unusual behavior, server sends "convended" without any data // if "flag stranger" packet is sent and no conversation have // been started before. // // Hence, we have to handle it like this. // ----------------------------------------------------------- IsStrangerConnected = false; if (packet.Data != null) { var di = new DisconnectInfo(true, int.Parse(packet.Data.ToString())); var eventArgs = new ConversationEndedEventArgs(di); ConversationEnded?.Invoke(this, eventArgs); } else { var di = new DisconnectInfo(true, -1); var eventArgs = new ConversationEndedEventArgs(di); ConversationEnded?.Invoke(this, eventArgs); } continue; } if (packet.Header == StrangerDisconnectedPacket.ToString()) { if (CurrentCID != packet.Data.ToString() && EncounteredClientIDs.Contains(packet.Data.ToString())) { EncounteredClientIDs.Remove(packet.Data.ToString()); continue; } IsStrangerConnected = false; if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } var di = new DisconnectInfo(false, int.Parse(packet.Data.ToString())); var eventArgs = new ConversationEndedEventArgs(di); ConversationEnded?.Invoke(this, eventArgs); continue; } if (packet.Header == MessageReceivedPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } int postId = -1; if (packet.AdditionalFields.ContainsKey("post_id")) { postId = int.Parse(packet.AdditionalFields["post_id"].ToString()); } var message = new Message( packet.Data["msg"].ToString(), int.Parse(packet.Data["cid"].ToString()), postId, MessageType.Chat ); var eventArgs = new MessageEventArgs(message); MessageReceived?.Invoke(this, eventArgs); continue; } if (packet.Header == OnlinePeopleCountPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } int number; if (!int.TryParse(packet.Data.ToString(), out number)) { number = -1; } var eventArgs = new OnlineCountEventArgs(number); OnlinePeopleCountChanged?.Invoke(this, eventArgs); continue; } if (packet.Header == PingPacket.ToString()) { if (KeepAlive) { PongResponse(); } var eventArgs = new PingEventArgs(DateTime.Now); PingReceived?.Invoke(this, eventArgs); continue; } if (packet.Header == RandomTopicReceivedPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } var message = new Message( packet.Data["topic"].ToString(), int.Parse(packet.Data["cid"].ToString()), int.Parse(packet.AdditionalFields["post_id"].ToString()), MessageType.Topic ); var eventArgs = new MessageEventArgs(message); MessageReceived?.Invoke(this, eventArgs); continue; } if (packet.Header == ServiceMessageReceivedPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } var message = new Message(packet.Data.ToString(), -1, -1, MessageType.Service); var eventArgs = new MessageEventArgs(message); MessageReceived?.Invoke(this, eventArgs); continue; } if (packet.Header == StrangerChatstatePacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } bool writing; if (!bool.TryParse(packet.Data.ToString(), out writing)) { writing = false; } var chatState = writing ? ChatState.Writing : ChatState.Idle; var eventArgs = new ChatstateEventArgs(chatState); StrangerChatstateChanged?.Invoke(this, eventArgs); continue; } if (packet.Header == StrangerFoundPacket.ToString()) { if (packet.Data == null) { throw new Exception("Invalid packet received, packet data is null."); } CurrentContactUID = packet.Data["ckey"].ToString(); SendPacket(new ConversationStartAcknowledged(CurrentContactUID)); ActionID++; EncounteredClientIDs.Add(packet.Data["cid"].ToString()); IsSearchingForStranger = false; IsStrangerConnected = true; var si = new StrangerInfo( int.Parse(packet.Data["cid"].ToString()), packet.Data["ckey"].ToString(), bool.Parse(packet.Data["flaged"].ToString()), packet.Data["info"] ); var eventArgs = new StrangerFoundEventArgs(si); StrangerFound?.Invoke(this, eventArgs); } } }
public bool WhatClubDoYouUsePingAhGood(object sender, PingEventArgs e) { _ping = true; return(true); }
private void ping_ChangeTimer(object sender, PingEventArgs pa) { //if (this.IsHandleCreated) //{ BeginInvoke(new MethodInvoker(delegate() { if (pa.Message().Contains("Approximate round trip times in milli-seconds")) { string[] ltimes = pa.Message().Split(new Char[] { '=' }); int enrs = ltimes.Length; string lval = ltimes[enrs - 1].Trim(); label12.Text = "Latency: " + lval; try { if (lval.Contains("ms")) { string valg = lval.Substring(0, lval.Length - 2); double dvalg = Convert.ToDouble(valg, CultureInfo.CurrentCulture); dataChart3.UpdateChart(dvalg); } } catch { ; } } })); //} }
public static bool OnPing (object sender, PingEventArgs e) { _ping = true; ++_pingCount; return true; }
private void ping_Change(object sender, PingEventArgs pa) { BeginInvoke(new MethodInvoker(delegate() { rtBox1.Text += "\n" + pa.Message(); })); }