2. Put in a timer (via alarm perhaps) or a counter (per transaction or per byte), killing the connection if you exceed a certain threshold. A properly designed protocol will limit the lengths of commands, and kill the connection when a bad command is seen.
3. Either construct a main() type of function to be called by the body of the application, or a one-time poll() type of function that you expect the application will call frequently. In the latter case, you could just do a select() to see if there's anything waiting, and if so, read it and process it, then return control to the application.
4. Be sure when you're doing your select processing that you go ahead and run through the entire list of waiting sockets before saying you're done. That will ensure everyone is handled.
5. That's probably more of a question about your higher-level design than anything else, and without more background about what your application is supposed to do, I can't offer any alternatives, but if your messages are small enough, even once a second is pretty trivial.
There are modules out there specifically for doing these types of things behind the scenes. NetServer::Generic I think is one of them. I'm not sure how it does with non-blocking sockets, but it's a good starting point for simple client-server types of apps. Good luck.
In reply to Re: Multiple clients with IO::Sockets
by Fastolfe
in thread Multiple clients with IO::Sockets, IO::Select
by swiftone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |