Java Network Service Scanner

无人久伴 提交于 2019-12-04 20:14:39

You could try connecting to the server explicitly by invoking Socket.connect( address, timeout ).

 Socket kkSocket = new Socket();
 kkSocket.bind( null )/ // bind socket to random local address, but you might not need to do this
 kkSocket.connect( new InetSocketAddress(iIPv4+i, port), 500 ); //timeout is in milliseconds
adrianboimvaser

You can create an unconnected socket using the noarg constructor Socket() and then call connect(SocketAddress endpoint, int timeout) with a small timeout value.

Socket socket = new Socket();
InetSocketAddress endpoint = new InetSocketAddress("localhost", 80);
int timeout = 1;
socket.connect(endpoint, timeout);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!