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 theTPSENDONLYflag 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 theTPRECVONLYflag set, resulting in the generation of aTPEV_SENDONLYevent. - The next call by B to
tprecv()returns a value of -1, setstperrno(5)toTPEEVENT, and returnsTPEV_SENDONLYin thereventargument, indicating that control has passed to B. - B calls
tpreturn()withrvalset toTPSUCCESS. This call generates aTPEV_SVCSUCCevent 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