Sunday, September 7, 2008

Java Socket client issue on Linux

In the case that the socket client is on the windows and server on linux & the server goes down, the client on windows identified immediately and gives an exception. For a scenario vice versa i.e. socket client on linux and server on any other machine (currently tested on windows), the client waits for too long for a timeout. To deal this situation instead of opening a socket client like:
 Socket socket = new Socket(“10.1.25.186”, 8080);
You should use:
InetAddress inetAddr = InetAddress.getByName(“navnit.tempo.local”);  
SocketAddress socAddr = new InetSocketAddress(inetAddr, 8080);  
Socket socket = new Socket();  socket.connect(socAddr, 5000); // 5000 is the timeout in millis.

No comments:

Post a Comment