COBOL Manual for TNS and TNS/R Programs
Process Initiation, Communication, and
Management
HP COBOL Manual for TNS and TNS/R Programs—522555-006
31-18
Simple Server Example
•
The OPEN SYNCDEPTH value in the requester process that opens the server
process must not exceed the sync value in the RECEIVE-CONTROL paragraph of
the server process.
•
Only one reply WRITE to each READ on $RECEIVE is allowed. If you fail to reply
to a message before you read the next one, the HP COBOL run-time routines send
a default reply. In this situation, you cannot reply to that earlier message.
•
A program can use $RECEIVE whether or not the program runs as a process pair.
•
The contents of the record area associated with $RECEIVE are subject to
modification by the HP COBOL run-time routines. Even if a process has not
requested delivery of system messages in the RECEIVE-CONTROL paragraph,
the run-time routines handle system messages in the $RECEIVE record area.
These unrequested messages are not delivered to the process. If a process
modifies the record area and then performs a read operation on $RECEIVE, the
portion of the record area beyond the actual received message can include residue
of such system messages.
•
If you want to know the length of the record you read from $RECEIVE, identify
them with RECORD IS VARYING... DEPENDING, which enables you to determine
the length of the message that was sent to $RECEIVE by the requester.
Simple Server Example
The simple server in Example 31-9 looks up items in a telephone directory.
Example 31-9. Simple Server (page 1 of 4)
IDENTIFICATION DIVISION.
PROGRAM-ID. BRIEF-EXAMPLE.
AUTHOR. ZANE COBOL.
DATE-WRITTEN. 29 February, 1988
DATE-COMPILED.
**************************************************************************
* This simple server performs telephone-book lookups. *
* Given a name, it reports the name and a number. *
* Given a number, it reports the number and a name. *
* It assumes that no two persons have the same number or the same name. *
**************************************************************************
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HP TXP System.
OBJECT-COMPUTER. HP TXP System.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
* Declaring MESSAGE-IN and MESSAGE-OUT separately allows us to
* redirect either or both for debugging during development.
SELECT MESSAGE-IN
ASSIGN TO $RECEIVE
FILE STATUS IS RECEIVE-FILE-STATUS.