Is there a unix-like select in Java

Discussion in 'Java' started by Amit, Oct 26, 2004.

  1. Amit

    Amit Guest

    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
     
    Amit, Oct 26, 2004
    #1
    1. Advertising

  2. Amit

    Grant Wagner Guest

    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 <>
     
    Grant Wagner, Oct 26, 2004
    #2
    1. Advertising

  3. Amit

    Guest

    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/api/java/nio/channels/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
     
    , Oct 26, 2004
    #3
  4. Amit

    Filip Larsen Guest

    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,
    --
    Filip Larsen
     
    Filip Larsen, Oct 26, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bengt Richter
    Replies:
    13
    Views:
    8,030
    Piet van Oostrum
    Sep 10, 2003
  2. Jonathan Fine
    Replies:
    4
    Views:
    850
    Jonathan Fine
    Mar 2, 2005
  3. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
  4. palmiere
    Replies:
    1
    Views:
    412
    Erwin Moller
    Feb 9, 2004
  5. Replies:
    13
    Views:
    250
Loading...

Share This Page