I have looked online at making a multi-threaded server in perl, but i cannot find any good ones that clearly explain how to create one. I have created a server and client in perl but i do not seem to be able to make it multi-threaded. Can someone help me?
+3
A:
Assuming you are using the Net::Server CPAN module (rather than rolling your own), you could make use of Net::Server::Coro to build a multi-threded server. Note that Net::Server can handle (pre)forking (i.e. multi-processes) servers and these may be easer to use.
Andrew Walker
2010-05-10 19:28:39
I have no idea how to use Net::Server. And I do not need a multi-thread server persay, but i am wanting to learn how to program. I am wanting a multi-thread server so multiple clients can connect and i can send them all commands
David
2010-05-10 19:58:34
You can use select to wait on events (including 'can_write') on multiple sockets, or one of the asynchronous event loop modules (AnyEvent, Coro, EV, Event, IO::Async, POE) to create a single process server that can handle multiple clients. Otherwise look into using fork to handle separate clients.
MkV
2010-05-10 20:33:13
would i use fork to send commands to all clients at the same time?
David
2010-05-11 01:09:13
A starting point for Net::Server would be to modify the code at http://search.cpan.org/~rhandom/Net-Server-0.97/lib/Net/Server.pod#SAMPLE_CODE (which echos input back to multiple clients) to do whatever it is you have already written. To give you more specific advice, I think we need to know what you want your sever to do. We could list asynchronous Perl libraries all day.
Andrew Walker
2010-05-11 08:07:23
+1
A:
I think POE might be what you're looking for. See the POE Cookbook for examples.
migmir
2010-05-10 20:01:49
I'd second this suggestion. If you want a server to be able to handle simultaneous communications with multiple clients then POE would be a good fit. It takes some effort to get your head around but it's worth it.
Grant McLean
2010-05-10 20:46:17