Non-blocking sockets?

Discussion in 'Java' started by fishfry, Feb 7, 2005.

  1. fishfry

    fishfry Guest

    I need to write a batch program that listens for commands on a socket
    .... in other words the main loop is

    check socket for special command
    handle request if present
    else do next iteration of normal batch processing.

    On a Unix system in C or Perl I'd use select() with a non-blocking
    socket.

    Can I do the equivalent in Java?

    Or if not, would I listen for socket requests in a separate thread? That
    seems like a Java-ish way to do it.
     
    fishfry, Feb 7, 2005
    #1
    1. Advertisements

  2. fishfry

    Aquila Deus Guest

    Read about java.nio.* (Selector, SelectionKey, SelectionChannel, ...)

    But I would simply use a separate thread or non-blocking IO with sleep
    (similiar to select()'s impl on non-SMP sys)
     
    Aquila Deus, Feb 7, 2005
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.