From 95850b205a8c7bd173a15bdb216e9756747b4eeb Mon Sep 17 00:00:00 2001 From: lidgren Date: Sun, 6 Nov 2011 09:24:08 +0000 Subject: [PATCH] Suppressed Connection Reset messages. Fixed Chat server sample. --- Lidgren.Network/NetPeer.Internal.cs | 6 ++++++ Samples/Chat/ChatServer/Program.cs | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index ba7d7aa..c767335 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -106,6 +106,11 @@ namespace Lidgren.Network m_socket.Blocking = false; m_socket.Bind(ep); + const uint IOC_IN = 0x80000000; + const uint IOC_VENDOR = 0x18000000; + uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; + m_socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null); + IPEndPoint boundEp = m_socket.LocalEndPoint as IPEndPoint; LogDebug("Socket bound to " + boundEp + ": " + m_socket.IsBound); m_listenPort = boundEp.Port; @@ -349,6 +354,7 @@ namespace Lidgren.Network // connection reset by peer, aka connection forcibly closed aka "ICMP port unreachable" // we should shut down the connection; but m_senderRemote seemingly cannot be trusted, so which connection should we shut down?! // So, what to do? + LogWarning("ConnectionReset"); return; } diff --git a/Samples/Chat/ChatServer/Program.cs b/Samples/Chat/ChatServer/Program.cs index fe87439..39ef7c9 100644 --- a/Samples/Chat/ChatServer/Program.cs +++ b/Samples/Chat/ChatServer/Program.cs @@ -71,10 +71,12 @@ namespace ChatServer List all = s_server.Connections; // get copy all.Remove(im.SenderConnection); - NetOutgoingMessage om = s_server.CreateMessage(); - om.Write(NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " said: " + chat); - - s_server.SendMessage(om, all, NetDeliveryMethod.ReliableOrdered, 0); + if (all.Count > 0) + { + NetOutgoingMessage om = s_server.CreateMessage(); + om.Write(NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " said: " + chat); + s_server.SendMessage(om, all, NetDeliveryMethod.ReliableOrdered, 0); + } break; default: Output("Unhandled type: " + im.MessageType + " " + im.LengthBytes + " bytes " + im.DeliveryMethod + "|" + im.SequenceChannel);