Non-blocking sockets?

F

fishfry

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

Aquila Deus

fishfry said:
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.

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)
 

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

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top