Skip to content

Commit

Permalink
Allow hostnames on ScsTcpClient
Browse files Browse the repository at this point in the history
When a hostname is entered the IPAddressParse will throw an exception, a
condition has been made so that it is treated appropiately
  • Loading branch information
angelcalvasp committed Sep 13, 2016
1 parent 6014284 commit 42d3fc1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Scs/Communication/Scs/Client/Tcp/ScsTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,32 @@ public ScsTcpClient(ScsTcpEndPoint serverEndPoint)
/// <returns>Ready communication channel to communicate</returns>
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);
}

}
}

0 comments on commit 42d3fc1

Please sign in to comment.