1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-15 06:36:30 +09:00

KeepAliveDelay removed; ping frequency doubled instead if no activity in 1.5 x ping frequency

This commit is contained in:
lidgren
2010-06-24 11:23:36 +00:00
parent 77d480e3cb
commit 51a4bfa5ea
5 changed files with 17 additions and 21 deletions

View File

@@ -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;

View File

@@ -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
}
}
/// <summary>
/// Gets or sets the number of seconds of inactivity before sending an extra ping packet as keepalive. This should be shorter than ping interval.
/// </summary>
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;
}
}
/// <summary>
/// Gets or sets the number of seconds of non-response before disconnecting because of time out. Cannot be changed once NetPeer is initialized.
/// </summary>

View File

@@ -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
//

View File

@@ -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 = "";
}
}
}

View File

@@ -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();