Guardian Programmer's Guide

Table Of Contents
Guardian Programmer’s Guide 421922-014
22 - 1
22
Writing a Server Program
This section describes programming techniques that are useful when writing server
programs. With Section 21, Writing a Requester Program, this section summarizes
many of the techniques and procedures described earlier in this manual. You should
be familiar with the information contained in Sections 1 through 20 before reading this
section.
In addition to introducing the functions of a server process and some of the more
common programming models, this section also describes how to add security to your
requester/server application by limiting the number of requesters that can open a
server and keeping track of which requesters have the server open.
The last part of this section provides sample server programs that form part of an
application with the requester program described and shown in Section 21, Writing a
Requester Program.
Functions of a Server Process
The most common use for server processes is in database applications, where a
server process provides a database service. This service is usually to perform some
application-dependent function on the database, such as reading a record or updating
an account.
Sections 2 through 5 of this guide describe how to access data files using Guardian
and Enscribe procedure calls. How a server reads requests from the requester using
the $RECEIVE file is described in Section 6, Communicating With Processes.
Multithreaded and Single-Threaded Servers
Servers can be single-threaded or multithreaded. In the single-threaded case, the
server process reads a message from $RECEIVE, processes it, replies to it, and then
reads the next message.
In a multithreaded server, the server process can read several messages and process
them concurrently. To reply to the correct message, the server uses message tags.
Figure 22-1 shows the difference between single-threaded and multithreaded servers.
For details of multithreaded servers, see Section 6, Communicating With Processes.
Note. Not all servers are database servers. The requester/server application design model is
general and can be used wherever it is desirable to separate functions of the application into
different processes.