Java Socket.setSoTimeout() doesn't timeout on connect -
i have problem have used setsotimeout(500)
set timeout of 0.5 second on connection , read time delays, not working , instead timeouts after 10 seconds kind of exception. , yes, ip valid in situation.
java.net.connectexception: connection timed out: connect
here code :
try { socket sock = new socket(ip, 42042); sock.setsotimeout(500); bufferedinputstream = new bufferedinputstream(sock.getinputstream()); thenames = thenames + is.read() + ";"; printwriter os = new printwriter(sock.getoutputstream()); } catch (ioexception e) { system.out.println(e + " | le serveur " + ip + " ne reponds pas."); }
socket.setsotimeout
sets read timeout. has nothing connect timeouts. if want lower default connect timeout:
socket sock = new socket(); sock.connect(new inetsocketaddress(ip, 42042), timeout);
where timeout
in milliseconds.
note: javadoc says 'a timeout of 0 interpreted infinite timeout,' not correct: interpreted platform default connect timeout, around minute. infinite timeouts apply reads. note can use connect()
reduce platform default, not increase it.
half second far short either connect timeout or read timeout.
Comments
Post a Comment