In this chapter we are going to look at a step-by-step process of writing TCP/IP applications with libassa. Along the line, we will build a logging server, a test client, and remote logging monitor to illustrate various points of discussion.
The BSD Socket wrappers found in libassa is an implementation of the Asynchronous Communication Design Patterns described in [MartinBuschmannRiehle97]. For on-line documentation, visit white papers repository of ACE package.
Our goal is to write a log server, assa-logd, similar to the UNIX syslogd. It would accept connections from libassa-based applications, receive their log messages and write them to the log files. We also would like to have a terminal-based remote monitor program, assa-logmon, that can connect to the log server and then select and receive log messages from any of the applications connected to the server. Because the remote logging capability is built into the library, our client application, log-client, would simply need to be configured to write its log information to the server instead of a file.
Applications to write:
assa-logd - log server.
assa-logmon - terminal-based log monitor.
log-client - client test program.
Applications connect to the server and send to it their log messages.
assa-logd writes log messages to the log files.
assa-logmon connects to assa-logd, requests the list of all applications that are sending their log messages to the server, selects one to monitor and receives the copies of all the messages for that particular application.
The log server should serve local to the host as well as remote connections both for the clients and monitors.
For clarity, we are going to keep the source code for the applications in their respective directories:
logserver/ | +--- server/ +--- monitor/ +--- client/
As described in Section 1.2.1, we start coding assa-logd with generating the stubs. You can modify an example of the Makefile in the same section for compilation.
% cd logserver/server % assa-genesis LogServer assa-genesis: Generating skeleton files ... Created: "LogServer-main.h" Created: "LogServer-main.cpp" Created: "LogServer.h" Created: "LogServer.cpp"
We start coding assa-logmon with generating the stub files.
% cd logserver/monitor % assa-genesis LogMon assa-genesis: Generating skeleton files ... Created: "LogMon-main.h" Created: "LogMon-main.cpp" Created: "LogMon.h" Created: "LogMon.cpp"