Chapter 2. Writing Network Applications

Table of Contents
2.1. Log Server Desing
2.2. Accepting Connection Requests with Acceptor
2.3. Connecting with Connector
2.4. Data I/O Over TCP/IP Transport Layer
2.5. I/O Multiplexing with Reactor
2.6. Reactor Event Loop

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.

2.1. Log Server Desing

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:

Figure 2-1. Log Server Connectivity Diagram

  1. Applications connect to the server and send to it their log messages.

  2. assa-logd writes log messages to the log files.

  3. 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:

         +--- server/
         +--- monitor/
         +--- client/

2.1.1. Log Server Setup

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"

2.1.2. Log Monitor Setup

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"

2.1.3. Test Client Setup

log-client is generated in a similar manner:

% cd logserver/client
% assa-genesis LogClient

assa-genesis: Generating skeleton files ...

Created: "LogClient-main.h"
Created: "LogClient-main.cpp"
Created: "LogClient.h"
Created: "LogClient.cpp"