I've written a tcp server based on the examples in Perl Cookbook and using IO::Socket::INET. It blocks on accept() and then forks to handle each new connection as they come in.
All that works fine. Connection are made and the server can receive and send data.while (($connection) = $server->accept()) { # do fork stuff
The problem is - each child process blocks while listening for data from the client.while(<$connection>) { # waits for data # handle the incoming message
i.e. the server cannot initiate sending data to the client until after it receives something.
This is a real problem as my clients are only sending data sporadically.Can the "listen" for each connection behave in a non-blocking fashion?
Basically, I'd like to test if there's a message and if so, process it. If not, however, I'd like to have the option to 'do other stuff' like sending messages back to the client if necessary. Oh, and sleep for a bit.In reply to non-blocking listen on a tcp server by monkeyfish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |