tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
SocketExtensions.cs
Go to the documentation of this file.
1using System.Net;
2using System.Net.Sockets;
3
5{
9 static class SocketExtensions
10 {
16 public static void BindTest(ushort port, bool includeIPv6)
17 {
18 using var socket = new Socket(
19 includeIPv6
20 ? AddressFamily.InterNetworkV6
21 : AddressFamily.InterNetwork,
22 SocketType.Stream,
23 ProtocolType.Tcp);
24 socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, true);
25 socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false);
26 if (includeIPv6)
27 socket.DualMode = true;
28
29 socket.Bind(
30 new IPEndPoint(
31 includeIPv6
32 ? IPAddress.IPv6Any
33 : IPAddress.Any,
34 port));
35 }
36 }
37}
Extension methods for the Socket class.
static void BindTest(ushort port, bool includeIPv6)
Attempt to exclusively bind to a given port .