Home > Archive > Java Help > March 2004 > Using readline ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I am writing a chat client - the client needs to check the socket for data
every, say 2 seconds (using timer).
The client has no problems reading output from the server, however if there
has been no data written since the last check, then socketinput.readLine
seems to hang (or block ??!?) and then the application just hangs.
I was wondering what I am doing wrong ? There seems no way of checking to
see if there is any data from the server without hanging the client.
Any input would be much appreciated!
Regrads,
Andrew.
| |
| Ryan Stewart 2004-03-27, 12:30 am |
| "Rig" <rig@NOSPAMcallnetuk.com> wrote in message
news:405ecf6e$0$3304$cc9e4d1f@news-text.dial.pipex.com...
> I am writing a chat client - the client needs to check the socket for data
> every, say 2 seconds (using timer).
>
> The client has no problems reading output from the server, however if
there
> has been no data written since the last check, then socketinput.readLine
> seems to hang (or block ??!?) and then the application just hangs.
>
> I was wondering what I am doing wrong ? There seems no way of checking to
> see if there is any data from the server without hanging the client.
>
> Any input would be much appreciated!
>
> Regrads,
>
> Andrew.
>
How about creating a separate thread for reading from the socket?
| |
|
|
"Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
news:lMednTKIr8LRQcPdRVn-iQ@texas.net...
> "Rig" <rig@NOSPAMcallnetuk.com> wrote in message
> news:405ecf6e$0$3304$cc9e4d1f@news-text.dial.pipex.com...
data[color=darkred]
> there
to[color=darkred]
> How about creating a separate thread for reading from the socket?
>
>
Won't this just "stop" the thread ??
How would I go about creating a thread to read the input?
Many thanks.
Andrew.
| |
| Carla Lamp 2004-03-27, 12:30 am |
| "Rig" <rig@NOSPAMcallnetuk.com> wrote in message news:<405f01ee$0$3307$cc9e4d1f@news-text.dial.pipex.com>...
> "Ryan Stewart" <zzanNOtozz@gSPAMo.com> wrote in message
> news:lMednTKIr8LRQcPdRVn-iQ@texas.net...
> data
> there
> to
>
> Won't this just "stop" the thread ??
>
> How would I go about creating a thread to read the input?
>
> Many thanks.
>
> Andrew.
Since it would be a separate thread, you wouldn't care that it is
stopped. To create the separate thread, you define a class that
implements java.lang.Runnable. You put all your input reading code in
the public void run ( ) method. Say you have an instance of this
class, runnable. Then you can create a thread with new Thread (
runnable ) . start ( ).
|
|
|
|
|