Xamarin Public Jenkins 6992685b86 Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
2015-11-10 14:54:39 +00:00

23 lines
454 B
C#

using System;
using System.Net;
using System.Net.Sockets;
namespace MonoTests.Helpers {
public static class NetworkHelpers
{
public static int FindFreePort ()
{
TcpListener l = new TcpListener(IPAddress.Loopback, 0);
l.Start();
int port = ((IPEndPoint)l.LocalEndpoint).Port;
l.Stop();
return port;
}
public static IPEndPoint LocalEphemeralEndPoint ()
{
return new IPEndPoint (IPAddress.Loopback, FindFreePort());
}
}
}