From 995e3d043b3652aa5a4ae3c8b2739d9039b36886 Mon Sep 17 00:00:00 2001 From: compujuckel Date: Wed, 29 Nov 2023 22:09:52 +0100 Subject: [PATCH] potentially fix certain SocketExceptions on the UDP socket on Windows --- AssettoServer/Network/Udp/ACUdpServer.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AssettoServer/Network/Udp/ACUdpServer.cs b/AssettoServer/Network/Udp/ACUdpServer.cs index 02c9ccb4..846192e8 100644 --- a/AssettoServer/Network/Udp/ACUdpServer.cs +++ b/AssettoServer/Network/Udp/ACUdpServer.cs @@ -53,7 +53,13 @@ public ACUdpServer(SessionManager sessionManager, protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Log.Information("Starting UDP server on port {Port}", _port); - + + // https://stackoverflow.com/questions/5199026/c-sharp-async-udp-listener-socketexception + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + _socket.IOControl(-1744830452 /* SIO_UDP_CONNRESET */, new byte[] { 0, 0, 0, 0 }, null); + } + _socket.Bind(new IPEndPoint(IPAddress.Any, _port)); await Task.Factory.StartNew(() => ReceiveLoop(stoppingToken), TaskCreationOptions.LongRunning); }