How to test that the IP port is reachable?

FrankLike 1150015857 at qq.com
Sat Apr 6 04:48:31 UTC 2019


On Saturday, 6 April 2019 at 03:24:04 UTC, FrankLike wrote:
> Hi,everyone,...

Do you have some better code than this?
----------------------------------------------------------------
import std.stdio;
import std.socket;

void main()
{
	testIPPort();
}
bool testIPPort()
{
	try
	{
		auto results = 
getAddressInfo("127.0.0.1",AddressInfoFlags.NUMERICHOST);
		auto sock = new Socket(results[0]);
		auto address = getAddress("127.0.0.1",8080);
		sock.connect(address[0]);
		writeln(address," connect ok");
		return true;
	}
	catch(SocketException e)
	{	return false;
	}
}
---------------------------------------
Thanks.


More information about the Digitalmars-d-learn mailing list