I consider this to be the basic class model for any language using classes to implement an asynchronous c/s model:
You have a class thread, from which three classes of threads inherit.
The first is the receiver-thread, which receives a command (from the socket), translates it into an internal state object equivalent to the command and stores it in the in-fifo queue.
The second is the sender-thread, which takes responses from the internal out-fifo and sends them to the applicable socket. It only does this. You can leave this one out, but it looks nicer (imo) if it's separated.
The third, and most important, is the worker thread. This one knows nothing of C/S or protocols or anything (hence the separation with the sender) and only receives a single command on the input-fifo to process onto the output-fifo. It does this in its own time.
A CS application consists of one (or more) reader threads, preferably sqr(n) readers for n sockets (so, each reader has x threads, and there are x readers). This kind of optimizes the speed the readers work at versus the select() system call. It has any random number of worker threads that suffices, but at least 1 for each processor of the machine. If it does mostly blocking operations (webserver, something like that) it needs more than one per processor. You can make it a parameter of the program. It needs some senders, but I have no numbers on how many. My guess is about 2-3 for most loads, since they work without delays.
Each has a pointer/reference to the main class of the program (of whatever name) so they can all use that one. It controls the sockets (also a class), and makes sure they are reconnected etc..
Each socket inherits from a base socket (which may or may not be standard for your language), and extends it by either a nicer interface or additional functions (such as encryption, compression etc.).
This pretty much describes your basic C/S program. If you're not doing this for your own enjoyment or some decent reason (but rather a school project etc.) make a single program that launches a socket-bound thread that processes a single operation at a time. It's slow and heavy on your server, but who cares? It's easiest to program
