Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Is there a unix-like select in Java (http://www.velocityreviews.com/forums/t137981-is-there-a-unix-like-select-in-java.html)

Amit 10-26-2004 05:06 PM

Is there a unix-like select in Java
 
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

Grant Wagner 10-26-2004 05:21 PM

Re: Is there a unix-like select in Java
 
Amit wrote:

> 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.

--
Grant Wagner <gwagner@agricoreunited.com>


shakahshakah@gmail.com 10-26-2004 06:32 PM

Re: Is there a unix-like select in Java
 
Have you checked out Java 1.4's NIO stuff, e.g.
java.nio.channels.Selector
(http://java.sun.com/j2se/1.4.2/docs/.../Selector.html)
?

Amit wrote:
> 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



Filip Larsen 10-26-2004 07:28 PM

Re: Is there a unix-like select in Java
 
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/JDCTec...04/tt0914.html


Regards,
--
Filip Larsen




All times are GMT. The time now is 06:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.