From 15a9a97ffb439bce0b177f3741666e614d929789 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Sat, 5 Sep 2015 10:56:17 +0300 Subject: [PATCH] Refactor NetPeer.Connect code to throw on non-resolvable address. --- Lidgren.Network/NetPeer.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Lidgren.Network/NetPeer.cs b/Lidgren.Network/NetPeer.cs index 8590e8e..3e59e2b 100644 --- a/Lidgren.Network/NetPeer.cs +++ b/Lidgren.Network/NetPeer.cs @@ -244,12 +244,20 @@ namespace Lidgren.Network Recycle(msg); } + static NetEndPoint GetNetEndPoint(string host, int port) + { + IPAddress address = NetUtility.Resolve(host); + if (address == null) + throw new NetException("Could not resolve host"); + return new NetEndPoint(address, port); + } + /// /// Create a connection to a remote endpoint /// public NetConnection Connect(string host, int port) { - return Connect(new NetEndPoint(NetUtility.Resolve(host), port), null); + return Connect(GetNetEndPoint(host, port), null); } /// @@ -257,7 +265,7 @@ namespace Lidgren.Network /// public NetConnection Connect(string host, int port, NetOutgoingMessage hailMessage) { - return Connect(new NetEndPoint(NetUtility.Resolve(host), port), hailMessage); + return Connect(GetNetEndPoint(host, port), hailMessage); } ///