From 42d3fc10ff1b29751fdb7764eec9243da0a2a564 Mon Sep 17 00:00:00 2001 From: Blacksun Date: Tue, 13 Sep 2016 09:54:25 -0500 Subject: [PATCH] Allow hostnames on ScsTcpClient When a hostname is entered the IPAddressParse will throw an exception, a condition has been made so that it is treated appropiately --- .../Scs/Client/Tcp/ScsTcpClient.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Scs/Communication/Scs/Client/Tcp/ScsTcpClient.cs b/src/Scs/Communication/Scs/Client/Tcp/ScsTcpClient.cs index 20ee206..b3c8b5f 100644 --- a/src/Scs/Communication/Scs/Client/Tcp/ScsTcpClient.cs +++ b/src/Scs/Communication/Scs/Client/Tcp/ScsTcpClient.cs @@ -30,11 +30,32 @@ public ScsTcpClient(ScsTcpEndPoint serverEndPoint) /// Ready communication channel to communicate protected override ICommunicationChannel CreateCommunicationChannel() { + + EndPoint endpoint = null; + + if (IsStringIp(_serverEndPoint.IpAddress)) + { + endpoint = new IPEndPoint(IPAddress.Parse(_serverEndPoint.IpAddress), _serverEndPoint.TcpPort); + } + else + { + endpoint = new DnsEndPoint(_serverEndPoint.IpAddress, _serverEndPoint.TcpPort); + } + return new TcpCommunicationChannel( TcpHelper.ConnectToServer( - new IPEndPoint(IPAddress.Parse(_serverEndPoint.IpAddress), _serverEndPoint.TcpPort), + endpoint, ConnectTimeout )); + + } + + private bool IsStringIp(string address) + { + IPAddress ipAddress = null; + return IPAddress.TryParse(address, out ipAddress); + } + } }