-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
Description
I want to crate a TcpConnectionListener to bind to the first free port. It works fine, however, I cannot get the port number:
listener = new TcpConnectionListener(new NetworkEndPoint(IPAddress.Loopback, 0));
int port = ((IPEndPoint)listener.EndPoint).Port; // 0
// reflection hack
var socket = ((Socket)listener.GetType().GetField("listener", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(listener));
port = ((IPEndPoint)socket.LocalEndPoint).Port; // 63930 - the real port numberNote: I want to use this for a Unity - other local process IPC.