Move port usage (#504)

* Moved port usage code check to before startup

* removed unused import

---------

Co-authored-by: Alex <clodanSPT@hotmail.com>
This commit is contained in:
clodanSPT
2025-07-23 08:44:34 +01:00
committed by GitHub
parent 2983edd51b
commit 2d752457b2
3 changed files with 15 additions and 32 deletions
+15 -1
View File
@@ -1,5 +1,5 @@
using System.Net;
using System.Runtime;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Text;
@@ -126,6 +126,20 @@ public static class Program
var httpConfig = options
.ApplicationServices.GetService<ConfigServer>()
?.GetConfig<HttpConfig>()!;
// Probe the http ip and port to see if its being used, this method will throw an exception and crash
// the server if the IP/Port combination is already in use
TcpListener? listener = null;
try
{
listener = new TcpListener(IPAddress.Parse(httpConfig.Ip), httpConfig.Port);
listener.Start();
}
finally
{
listener?.Stop();
}
var certHelper = options.ApplicationServices.GetService<CertificateHelper>()!;
options.Listen(
IPAddress.Parse(httpConfig.Ip),