Creating a Java Socket Takes More Time

I gave Socket soc = new Socket(host,port); Now that the host computer is in a running state, the socket is created immediately.

But when the computer is turned off or restarted, it takes about 40 seconds to answer this line. I tried using soc.setSoTimeout(timeout); But this line is used after creating the Socket. Therefore, this does not help much.

Also this seems like a bug in JAVA. http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=5092063

I tried several workarounds provided in this link, for example, adding the machine port and hostname to the etc / hosts file. But that will not work. Due to this delay, due to DNS resolution when creating a socket, the response time to my system will suffer greatly.

Any help would be greatly appreciated.

thanks sr

+4
source share
1 answer

Use the connect with timeout method

 // create an unconnected socket Socket soc = new Socket(); soc.setSoTimeout(SO_TIMEOUT); // if you like // connect (with timeout) soc.connect(new InetSocketAddress(host, port), CONNECT_TIMEOUT); 
+8
source

All Articles