• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing objects via sockets  RSS feed

 
Brett Anthoine
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have the following problem :
I've got a piece of code checking for information from a server via a ObectInputStream, say every 2 secs.
My problem is I don't want the Thread to hang on waiting for ever if the stream is empty, so i tried the following :

Message is a very simple class with some String and int fields.
Anyway, my available() return value seems to always be 0 , even if there is data available.
Help
Thank you
ps : by the way I don't like to check my stream every 2 seconds, is there a way to register a kind of listeners on the stream an generate an event when something is arriving ?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you want (unless you start fiddling with socket timeouts) is available in version 1.4 of the Java SDK. Look into the java.nio.* package.
- Peter
 
Brett Anthoine
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter,
I'm investigating in that way. If someone is interessted, check this link
Merlin non blocking IOs Javaworld's article
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great link! Thanks --
- Peter
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!