Is there a unix-like select in Java

A

Amit

Hi all:

I was wondering if Java took care of the classic problem that is used
to introduce select in unix (as in Stevens book). The problem is of
echo client and server. If suppose the server wants to close down, it
sends a FIN to the client. However, the client may be busy-waiting
for user to enter smth. When user enters smth, the client tries to
write, only to find that the connection has been closed from server's
side. So, we unnecessarily made the user to enter smth. What we want
is that as soon as the FIN comes, we are notified. selects fits here.

select is a fn that is used to listen to one or more descriptors. When
there is data on any one of them, we are notified. This way, as soon
as the server closes down, the client gets to know about it.

Is there smth of this sort in java.

Thanks

Amit
 
G

Grant Wagner

Amit said:
Hi all:

I was wondering if Java took care of the classic problem that is used
to introduce select in unix (as in Stevens book). The problem is of
echo client and server. If suppose the server wants to close down, it
sends a FIN to the client. However, the client may be busy-waiting
for user to enter smth. When user enters smth, the client tries to
write, only to find that the connection has been closed from server's
side. So, we unnecessarily made the user to enter smth. What we want
is that as soon as the FIN comes, we are notified. selects fits here.

select is a fn that is used to listen to one or more descriptors. When
there is data on any one of them, we are notified. This way, as soon
as the server closes down, the client gets to know about it.

Is there smth of this sort in java.

Thanks

Amit

Start a separate thread that always listens to the server, if it receives
information from the server while another thread is doing something else,
it can take the appropriate action (display a message, reconnect, connect
to a different server, etc).

And does typing "smth" instead of "something" save you that much time and
effort? Personally I had to stop and _think_ about typing "smth", the word
"something" actually results in a higher wpm rate. And I don't think
anyone is going to chastise you for "wasting" 5 characters.
 
F

Filip Larsen

Amit wrote
select is a fn that is used to listen to one or more descriptors. When
there is data on any one of them, we are notified. This way, as soon
as the server closes down, the client gets to know about it.

Is there smth of this sort in java.

In Java 1.4 the new packages in java.nio and below introduced Selectors,
SelectableChannel and SelectionKey that corresponds more or less to
select on *nix. Don't forget to read the documentation before you use
them, because there are some pitsfall:

http://java.sun.com/j2se/1.4.2/docs/guide/nio/
http://java.sun.com/developer/JDCTechTips/2004/tt0914.html


Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top