• Post Reply Bookmark Topic Watch Topic
  • New Topic

Send object via socket with timeout

 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I developed an application that send objects to instance of itself on other computer via network, using sockets - and it works great!

I use something like



and some ServerSocket on the destination PC accepts this object, process it and does everything that it's supposed to do.

BUT:

When the server that excepts this object is not started or rechable because of some other reason, it takes several seconds ( something about 5 - 20 secons) to try to send it, and after that ( long) time it moves on with the work...
What I would like to know is :
Is there some way to set some timeout for an application trying to send object?

Something like public void sendObject(Object obj, int timeout) // try to send this object, but just for timeout seconds!
 
Shawn Montague
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out socket.setSOTimeout(). There ares some other things you can do as well, like mess with TCP delay
 
Shawn Montague
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that is actually: setSoTimeout().
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shawn Montague wrote:Sorry, that is actually: setSoTimeout().


Michael is writing to a socket, and SO_TIMEOUT apparently controls the timeout on a read:

With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time.


java.net.Socket
 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers...

Anything else...?
 
Paul Clapham
Sheriff
Posts: 21867
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that you have answers, it isn't easy to tell what "anything else?" means. Does it mean the answers didn't solve your problem? Does it mean that you haven't done anything with them but you're trying to collect a lot of answers before you try any of them? It's time for you to clarify where your problem stands. And to ask a more precise follow-up question than that.
 
Michael Brown
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Now that you have answers, it isn't easy to tell what "anything else?" means. Does it mean the answers didn't solve your problem? Does it mean that you haven't done anything with them but you're trying to collect a lot of answers before you try any of them? It's time for you to clarify where your problem stands. And to ask a more precise follow-up question than that.


I don't have answers, I have an answer which , by the way, didn't solve my problem.

I was aware of setSOTimeout() before but , like Joe Ess pasted here:

With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time.


and I need this when trying to send objects.

So, yes, my "anything else?" means "This answr didn't solve my problem. Is there anything else you could suggest to me?"
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, Paul is making reference to our FAQ PatienceIsAVirtue:
And if you finally decide to bump the post, please try to do so by posting more information! After all, if nobody answered, that's probably because nobody did know an answer. You had 24 hours to do your own research in the mean time - show us that you used them, and give us new things to think about. If nothing else, work harder to TellTheDetails.


I can see your point that there aren't many more details to your situation.
Try setting the sun.net.client.defaultConnectTimeout system property:
sun.net.client.defaultConnectTimeout specifies the timeout (in milliseconds) to establish the connection to the host. For example for http connections it is the timeout when establishing the connection to the http server. For ftp connection it is the timeout when establishing the connection to ftp servers.

Java Networking Properties
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!