1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-18 16:16:35 +09:00

Refactor NetPeer.Connect code to throw on non-resolvable address.

This commit is contained in:
Marius Ungureanu
2015-09-05 10:56:17 +03:00
parent 2d1f9a4b91
commit 15a9a97ffb

View File

@@ -244,12 +244,20 @@ namespace Lidgren.Network
Recycle(msg); 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);
}
/// <summary> /// <summary>
/// Create a connection to a remote endpoint /// Create a connection to a remote endpoint
/// </summary> /// </summary>
public NetConnection Connect(string host, int port) public NetConnection Connect(string host, int port)
{ {
return Connect(new NetEndPoint(NetUtility.Resolve(host), port), null); return Connect(GetNetEndPoint(host, port), null);
} }
/// <summary> /// <summary>
@@ -257,7 +265,7 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public NetConnection Connect(string host, int port, NetOutgoingMessage hailMessage) public NetConnection Connect(string host, int port, NetOutgoingMessage hailMessage)
{ {
return Connect(new NetEndPoint(NetUtility.Resolve(host), port), hailMessage); return Connect(GetNetEndPoint(host, port), hailMessage);
} }
/// <summary> /// <summary>