IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080); string url = endpoint.ToHttpUrl();
TcpListener listener = new TcpListener(IPAddress.Any, 8080); listener.Start(); IPEndPoint endpoint = (IPEndPoint)listener.LocalEndpoint; string url = endpoint.ToHttpUrl();In this example, we create a TcpListener object that listens for incoming connections on any available IP address and on port number 8080. We then retrieve the local endpoint of the listener using the LocalEndpoint property and convert it to a URL using the ToHttpUrl method. The System.Net namespace is included in the .NET Framework class library.