Files
soccar2d/Assets/Scripts/Utils/GetAvailablePort.cs
T
2026-09-24 13:12:15 +05:30

20 lines
366 B
C#

using System.Net;
using System.Net.Sockets;
public static class GetAvailablePort
{
public static int GetAvailableUdpPort()
{
using var socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp
);
socket.Bind(new IPEndPoint(IPAddress.Any, 0));
return ((IPEndPoint)socket.LocalEndPoint).Port;
}
}