From a74c55dc671171505122a7da6e1004afdbf11cfa Mon Sep 17 00:00:00 2001 From: Patrick Ritchie Date: Mon, 24 Jul 2023 19:32:36 -0400 Subject: [PATCH] Update to allow Hostname as Http Server --- .../Servers/MTConnectHttpServer.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs b/src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs index cf6d3923..34bd5a3a 100644 --- a/src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs +++ b/src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs @@ -7,6 +7,7 @@ using MTConnect.Configurations; using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.Http; using System.Security.Cryptography.X509Certificates; @@ -174,10 +175,18 @@ private async Task StartServer(IHttpServerConfiguration serverConfiguration, Can } } - EndPoint endpoint; + EndPoint endpoint = null; if (!string.IsNullOrEmpty(serverConfiguration.Server)) { - endpoint = new DnsEndPoint(serverConfiguration.Server, serverConfiguration.Port); + var hostEntry = Dns.GetHostEntry(serverConfiguration.Server); + if (hostEntry != null && !hostEntry.AddressList.IsNullOrEmpty()) + { + var hostAddress = hostEntry.AddressList.FirstOrDefault(o => o.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); + if (hostAddress != null) + { + endpoint = new IPEndPoint(hostAddress, serverConfiguration.Port); + } + } } else endpoint = new IPEndPoint(IPAddress.Any, serverConfiguration.Port);