Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 13
Sending, Receiving, and Replying to Messages:
An Example
6 Communicating With Processes
Sending, Receiving, and Replying to Messages: An Example
In the example shown in Figure 6-4, the server process sends a reply back to the
requester. This example allows the user of the terminal running the requester process
to query the user of the terminal running the server process. The purpose of the
example is to show the concept. The long example at the end of this section shows a
practical use.
The programs work like this: Initially, the requester prompts its terminal user for
message input using WRITEREADX, and then it sends the message to the server.
The server (which has opened the $RECEIVE file with a receive depth of 1) uses the
READUPDATEX procedure to read the message from $RECEIVE so as not to
terminate the requester’s WRITEREADX without reply data. The server displays the
received message on its home terminal using WRITEREADX, which solicits a reply
from the terminal user. The server process then returns the reply to the requester
using the REPLYX procedure. Finally, the requester displays the reply on its home
terminal and waits for further input from the user. Both processes terminate when the
server user types “EXIT.”
Closing $RECEIVE
You explicitly close $RECEIVE as you would any file using the FILE_CLOSE_
procedure:
ERROR := FILE_CLOSE_(RECV^NUM);
IF ERROR <> 0 THEN ...
As for any file, if you do not explicitly close $RECEIVE, then the file is implicitly closed
when the process terminates.