private static void PingTest(PortalClient c) { if (Closing || !c.IsAlive) { return; } var count = 0; do { Portal.ToConsole("Test: Enter the number of ping requests to send..."); }while (!Closing && c.IsAlive && (!Int32.TryParse(Console.ReadLine(), out count) || count < 0)); if (Closing || !c.IsAlive) { Portal.ToConsole("Test: Skipped ping testing..."); return; } if (count <= 0) { Portal.ToConsole("Test: Skipped ping testing..."); return; } var samples = new long[count]; Portal.ToConsole("Ping: {0:#,0} requests...", samples.Length); var time = 0L; var watch = new Stopwatch(); for (var i = 0; i < samples.Length; i++) { watch.Start(); Portal.ToConsole("Ping: ..."); var result = c.Ping(false); watch.Stop(); samples[i] = watch.ElapsedMilliseconds; watch.Reset(); time += samples[i]; Portal.ToConsole("Pong: {0:#,0}ms", samples[i]); if (!result) { break; } } Portal.ToConsole("Completed: T:{0:#,0}ms A:{1:#,0}ms", time, time / samples.Length); PingTest(c); }
private static void OnPingRequest(PortalClient client, PortalPacketReader p) { //p.ReadToEnd(); // random bytes client.Ping(true); }