The main reason servers are typically more complex is that they serve multiple clients. Servers usually are initiated upon the first linkage request from a client. There are usually critical sections and other locking issues to consider. Servers must provide graceful termination of clients if a service is terminated. Some simple services are still implemented using a server library.
Server Libraries
This is the simplest form of a server. The program requires an EXPORT list, which defines the collection of available library objects, and a FREEZE statement, which defines the point in the execution logic that the service is available. This implementation strategy is supported by most languages implementing libraries, although in many cases, the FREEZE statement is performed implicitly.
Examples
The following is an example of an ALGOL EXPORT list:
PROCEDURE REQUEST (BUF); ARRAY BUF [*]; BEGIN . . . END REQUEST; EXPORT REQUEST; FREEZE (TEMPORARY);
The following is an example of a COBOL EXPORT list:
IDENTIFICATION DIVISION. PROGRAM-ID. REQUEST. DATA DIVISION. WORKING STORAGE SECTION. 77 BUF PIC X(80). PROCEDURE DIVISION USING BUF. . . .
Connection Libraries
This is an advanced server, only available in ALGOL and NEWP. The program requires a connection block TYPE declaration, which holds declarations for the LIBRARY OBJECTS that make up the interface, a LIBRARY interface declaration of the connection library type, and a READYCL statement for that library interface.
Example
The following is an example of an ALGOL connection block TYPE declaration:
TYPE CONNECTION BLOCK SERVICETYPE; BEGIN PROCEDURE REQUEST (BUF); ARRAY BUF [*]; BEGIN . . . END REQUEST; EXPORT REQUEST; END SERVICETYPE; SERVICETYPE LIBRARY SERVICE; READYCL (SERVICE);
The reasons for choosing a connection library over a server library are
-
The interface declaration is contained inside the connection library type declaration.
-
The interface definition specifies the export of library objects in addition to the imported objects. These implement advanced concepts such as callback functions and client handlers for service events. However, using two-way connections can cause performance problems. For more information, refer to Hazards of Circular Connections.
-
Declarations local to the connection block TYPE declaration are instantaneous for each connection, providing an efficient mechanism to track and save client information. To achieve similar function with server libraries, either a mechanism detecting client identity and locating state information is invoked on every client call referencing local state, or the server is implemented as a private library. This assures a server instance per client, but possibly strains system resources and management.

