Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: How to serve multiple socket clients Perlby sundialsvc4 (Abbot) |
on Mar 23, 2015 at 14:33 UTC ( [id://1120990]=note: print w/replies, xml ) | Need Help?? |
You really can’t have “searched the net with no results.” :-) There are literally thousands of servers out there which are all implemented in mostly the exact same way: with a select() loop. (Many of them are built using existing server-building toolkits, such as the great-many ... say, POE ... that are available for Perl. (Or, say, Twisted ... every language has several to choose from.) “Actum Ne Agas: Do not do a thing already done.™”) Conceptually speaking, the server sits there listening for incoming packets from any one of many simultaneously-open sockets. (A single thread is doing this!) When a packet arrives from any one of the sockets, the message is read, processed, and a reply is sent back on that socket. Meanwhile, the server is also listening for new connection-requests. If the replies can be made within a few milliseconds, nothing more than a single thread is needed. If the tasks that can be requested are such that it takes more than a trivial amount of time to do them, the server’s architecture becomes a little more complicated, because it is now managing a pool of worker-threads. Apache Server (or any web-server, for that matter) is a quintessential example of this. The key point is to realize that whatever-it-is that you’re doing is not a new use-case, therefore you really don’t have to “invent” anything. There is nothing to “build” here, and, since the available software is all free, nothing to “buy.” Extremely sophisticated and battle-tested servers, and clients, can simply be lifted off the shelf. To begin (in the case of Perl), surf to http://search.cpan.org and type the word server ...
In Section
Seekers of Perl Wisdom
|
|