7.5.1 Example: Ending a Simple Conversation
The following figure shows a simple conversation between A and B that terminates gracefully.
Figure 7-2 Simple Conversation Terminated Gracefully

The program flow is as follows:
- A sets up the connection by calling
tpconnect()
with theTPSENDONLY
flag set, indicating that process B is on the receiving end of the conversation. - A turns control of the connection over to B by calling
tpsend()
with theTPRECVONLY
flag set, resulting in the generation of aTPEV_SENDONLY
event. - The next call by B to
tprecv()
returns a value of -1, setstperrno(5)
toTPEEVENT
, and returnsTPEV_SENDONLY
in therevent
argument, indicating that control has passed to B. - B calls
tpreturn()
withrval
set toTPSUCCESS
. This call generates aTPEV_SVCSUCC
event for A and gracefully brings down the connection. - A calls
tprecv()
, learns of the event, and recognizes that the conversation has been terminated. Data can be received on this call totprecv()
even if the event is set toTPEV_SVCFAIL
.
Note:
In this example, A can be either a client or a server, but B must be a server.Parent topic: Ending a Conversation