From 51a4bfa5eaa3aec09c7045304645d5344f0c8d7b Mon Sep 17 00:00:00 2001 From: lidgren Date: Thu, 24 Jun 2010 11:23:36 +0000 Subject: [PATCH] KeepAliveDelay removed; ping frequency doubled instead if no activity in 1.5 x ping frequency --- Lidgren.Network/NetConnection.Latency.cs | 11 ++++++----- Lidgren.Network/NetPeerConfiguration.cs | 16 ---------------- Samples/ChatClient/Form1.Designer.cs | 1 + Samples/ChatClient/Form1.cs | 7 +++++++ Samples/ChatClient/Program.cs | 3 +++ 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Lidgren.Network/NetConnection.Latency.cs b/Lidgren.Network/NetConnection.Latency.cs index 52e142a..fa5ca35 100644 --- a/Lidgren.Network/NetConnection.Latency.cs +++ b/Lidgren.Network/NetConnection.Latency.cs @@ -111,10 +111,6 @@ namespace Lidgren.Network if (m_status == NetConnectionStatus.Disconnected || m_status == NetConnectionStatus.None) return; - // in case of inactivity; send forced keepalive/ping - if (now > m_lastSendRespondedTo + m_peerConfiguration.m_keepAliveDelay) - m_nextPing = now; - // force ack sending? if (now > m_nextForceAckTime) { @@ -141,7 +137,12 @@ namespace Lidgren.Network now = NetTime.Now; // need exact number m_lastSentPingNumber++; m_lastPingSendTime = now; - m_nextPing = now + m_owner.Configuration.m_pingFrequency; + + // in case of not heard for a while + if (now > m_lastSendRespondedTo + (m_owner.Configuration.m_pingFrequency * 1.5f)) + m_nextPing = now + (m_owner.Configuration.m_pingFrequency * 0.5f); // double ping rate + else + m_nextPing = now + m_owner.Configuration.m_pingFrequency; NetOutgoingMessage ping = m_owner.CreateMessage(1); ping.m_libType = NetMessageLibraryType.Ping; diff --git a/Lidgren.Network/NetPeerConfiguration.cs b/Lidgren.Network/NetPeerConfiguration.cs index 38aceb2..b4792da 100644 --- a/Lidgren.Network/NetPeerConfiguration.cs +++ b/Lidgren.Network/NetPeerConfiguration.cs @@ -48,7 +48,6 @@ namespace Lidgren.Network internal float m_handshakeAttemptDelay; internal int m_handshakeMaxAttempts; internal float m_connectionTimeout; - internal float m_keepAliveDelay; internal float m_pingFrequency; // reliability @@ -73,7 +72,6 @@ namespace Lidgren.Network m_port = 0; m_receiveBufferSize = 131071; m_sendBufferSize = 131071; - m_keepAliveDelay = 4.0f; m_connectionTimeout = 25; m_maximumConnections = 16; m_defaultOutgoingMessageCapacity = 8; @@ -320,20 +318,6 @@ namespace Lidgren.Network } } - /// - /// Gets or sets the number of seconds of inactivity before sending an extra ping packet as keepalive. This should be shorter than ping interval. - /// - public float KeepAliveDelay - { - get { return m_keepAliveDelay; } - set - { - if (value < m_pingFrequency) - throw new NetException("Setting KeepAliveDelay to lower than ping frequency doesn't make sense!"); - m_keepAliveDelay = value; - } - } - /// /// Gets or sets the number of seconds of non-response before disconnecting because of time out. Cannot be changed once NetPeer is initialized. /// diff --git a/Samples/ChatClient/Form1.Designer.cs b/Samples/ChatClient/Form1.Designer.cs index b83d283..05e9b68 100644 --- a/Samples/ChatClient/Form1.Designer.cs +++ b/Samples/ChatClient/Form1.Designer.cs @@ -63,6 +63,7 @@ this.button1.TabIndex = 2; this.button1.Text = "Send"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // diff --git a/Samples/ChatClient/Form1.cs b/Samples/ChatClient/Form1.cs index a835a03..6aaf270 100644 --- a/Samples/ChatClient/Form1.cs +++ b/Samples/ChatClient/Form1.cs @@ -38,5 +38,12 @@ namespace ChatClient else Program.SettingsWindow.Show(); } + + private void button1_Click(object sender, EventArgs e) + { + string txt = textBox1.Text.Trim(); + Program.Input(txt); + textBox1.Text = ""; + } } } diff --git a/Samples/ChatClient/Program.cs b/Samples/ChatClient/Program.cs index e61e9a7..4f52bad 100644 --- a/Samples/ChatClient/Program.cs +++ b/Samples/ChatClient/Program.cs @@ -44,6 +44,9 @@ namespace ChatClient public static void Input(string input) { + if (string.IsNullOrEmpty(input)) + return; + if (input.ToLowerInvariant().StartsWith("connect ")) { string host = input.Substring(8).Trim();