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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user