Skip to content

Commit

Permalink
Update to allow Hostname as Http Server
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Jul 24, 2023
1 parent 9efa1ad commit a74c55d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a74c55d

Please sign in to comment.