hs2d
hs2d

Reputation: 6199

Java, increase the socket timeout

I have a simple server client application. Everything works, but at some stage it takes more than 5 minutes to get response from server (which is normal and it needs to be like this). The problem is that if it takes more than 5 minutes I keep getting this exception: java.net.SocketTimeoutException: Read timed out.

So I was wondering if there is some default socket timeout on windows or on the Java virtual machine I could set? I can't change the client code so setSoTimeout() is not an option for me.

Using Windows XP..

EDIT: As i understand now is that the socket connection is not opened in the client side. Its passed on from the server. So i decompiled allso the server jar file. But still cant find anything about the timeout.

Upvotes: 13

Views: 42947

Answers (4)

ssedano
ssedano

Reputation: 8432

And do you need to keep the connection alive? Why don't you rethink it to make it more asynchronous. That schema is not scaling at all. At one point all of your available threads could be waiting for a long time response from server.

Upvotes: 0

stivlo
stivlo

Reputation: 85546

The default socket timeout is 0, which means never timeout. If it actually time out after 5 minutes, it means it has been set within the code. If the source isn't available, and there isn't a configuration, you can try to decompile the class, and look for setSoTimeout calls.

Since the comments, and the fact that searches didn't find any setSoTimeout() calls, you can take a different approach. Just let it time out, and write a small script that will retry the call in case it does. If you can call your client from the command line, you can parse the output, if it goes on stderr.

Upvotes: 14

Lycha
Lycha

Reputation: 10187

Keeping unused TCP connection open for long time without any traffic isn't that trivial. Many firewalls/routers close the unused ports after some timeout.

One option could be to implement simple keepalive protocol to send dummy-packets every now and then, but if you can't touch the client code this is probably not an option.

Edit: I am not aware of any way to override setSoTimeout() set in the client code.

Upvotes: 8

Haris Krajina
Haris Krajina

Reputation: 15296

Answer that 0 is default timeout is not quite true. Since for example Axis2 client has default 60 seconds timeout, so it will depend on what kind of implementation you are using to make the call.

Can you provide more details? Sorry for writing in answers section but I don't have enough reputation to do comments :)

Upvotes: 0

Related Questions