Guardian Programmer's Guide

Table Of Contents
Using the Sequential Input/Output Procedures
Guardian Programmer’s Guide 421922-014
15 - 47
Passing Messages and Reply Text
Between Processes
Sending and Receiving Messages in Two-Way
Communication: An Example
Figure 15-5 shows an example of two-way communication between a requester
process and a server process. These processes pass data between terminal users in
both directions.
Each process reads some data from its input file and then sends the data to its output
file and waits for a response. On receiving the response, the server process sends the
response to its input file.
At run time, the requester process is assigned the server process as its output file; its
input file defaults to the home terminal. The server process takes $RECEIVE as its
input file and defaults its output file to its home terminal.
Data exchange between the requester and server processes takes place as follows:
1. The requester process prompts its terminal user for some data by issuing a
READ^FILE procedure call. The user’s response is returned in the read buffer.
2. The requester sends the user’s message to the server by issuing a READ^FILE
procedure call against the $SERV file. This call also waits for a response from the
server.
3. Meanwhile, the server has been waiting on the READ^FILE call for a message on
$RECEIVE. It now receives the message from the requester.
4. The server processes the message by sending it to its home terminal using a
READ^FILE procedure call. The READ^FILE procedure waits for a response from
the terminal user.
5. The server process sends the reply back to the requester by issuing a
WRITE^FILE procedure call against the $RECEIVE file.
Figure 15-5. Requester and Server Processes in Two-Way Communication
VST076.VSD
.
.
DO
BEGIN
CALL READ^FILE
(INFILE,BUFFER,COUNT,,40);
CALL READ^FILE
(OUTFILE,BUFFER,COUNT,40,40);
CALL WRITE^FILE
(INFILE,BUFFER,COUNT,ERROR);
END
UNTIL BUFFER = “EXIT”;
.
.
.
.
DO
BEGIN
CALL READ^FILE
(INFILE,BUFFER,COUNT,,40);
CALL READ^FILE
(OUTFILE,BUFFER,COUNT,,40);
CALL WRITE^FILE
(INFILE,BUFFER,COUNT,ERROR);
END
UNTIL BUFFER = “EXIT”;
.
.
Mes
sa
ge
Reply