in reply to How to serve multiple socket clients Perl
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 ...
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to serve multiple socket clients Perl
by perlnwb (Initiate) on Mar 23, 2015 at 20:38 UTC | |
by Anonymous Monk on Mar 23, 2015 at 21:01 UTC | |
by Anonymous Monk on Mar 25, 2015 at 16:28 UTC | |
by Anonymous Monk on Mar 23, 2015 at 22:08 UTC |