It's normal in the Unix world for server processes to be invoked
by harness programs such as
in such a way that the server sees commands on standard input and
ships responses to standard output; the harness program then takes
care of ensuring that the server's stdin and stdout are connected to a
service port. One benefit of this division of labor is that the
harness program can act as a single security gatekeeper for all of the
servers it launches.
One of the classic interface patterns is therefore a CLI server.
This is a program which, when invoked in a foreground mode, has a
simple CLI interface reading from standard input and writing to
standard output. When backgrounded, the server detects this and
connects its standard input and standard output to a specified
In some variants of this pattern, the server backgrounds itself
by default, and has to be told with a command-line switch when it
should stay in foreground. This is a detail; the essential point is
that most of the code neither knows nor cares whether it is running in
foreground or a TCP/IP
POP, IMAP, SMTP, and HTTP servers normally obey this pattern.
It can be combined with any of the server/client patterns described
earlier in this chapter. An HTTP server can also act as a harness
program; the CGI scripts that supply most live content on the Web run
in a special environment provided by the server where they can take
input (form arguments) from standard input, and write the generated
HTML that is their result to standard output.
Though this pattern is quite traditional, the term “CLI
server” is my invention.