This discussion is archived
3 Replies Latest reply: Jun 11, 2008 1:44 AM by 807591 RSS

How can i tell read() method from bufferedReader to wait 30s for a stream?

807591 Newbie
Currently Being Moderated
I have a simple code that sends an receives messages to and from a server. But when i try to read the message from the server it blocks/hangs on read(), waiting for a response. How can i tell the applicaton to wait 30 seconds and if nothing comes from the server, to shut the socket?
I tried the ready() method but it finished too fast, it doesn't wait long enough. I also tried to make a new thread that waits 30 seconds and than shuts the socket, but it is not efficient for my program (it takes up too many resources and i can't afford it).
I used a while loop, but useless...it does not go further than read().
If you have any idea, please let me know.

Thank you

Edited by: casiopeea on Jun 11, 2008 1:28 AM