[3274] in java-interest
Reading information from a socket AND the keyboard -- A real
daemon@ATHENA.MIT.EDU (Mike Afergan)
Sun Nov 5 21:04:15 1995
Date: Sun, 5 Nov 95 19:14:06 EST
To: java-interest@java.sun.com
From: Mike Afergan <mikea@abba.ai.mit.edu>
I'll keep this real simple:
Note: Still using Alpha3.
I'm writing an applet that has two sources of information: the user and a
socket
connection. Each time the user presses a key, the applet will respond
through my
keyDown(). I have also written a group of methods to handle the information
coming across the socket.
My problem is this: I need to check both sources constantly, but even with
threads, the applet interface seems rather malsuited for this task. If I
just had the
keyboard interface, the applet would "sleep" until a key was depressed.
However,
there is no such "gotSocketInfo()" method.
I considered using a separate thread to get the information in the
background.
Nevertheless, I would need to designate a certain time to check for new
information
from the thread.
This problem may be too easy, but it boils down to a simple question. Is
there a
simple way to do a given task on a regular interval (i.e., every 5 seconds)?
(It
would be better if the key was the reception of new information, but I can
settle for
checking the stream every five seconds for now.)
If there is a way to check the stream at a given interval, will
n = mc.serverInput.read(buf, 0, buf.length);
cause my applet to hang if there is no new information in the stream?
Am I perhaps missing a better solution?
Any suggestions, comments would be greatly appreciated.
Thanks,
-- Mike
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com