Table of Contents
This chapter describes the communication modes supported by Tmax.
Tmax supports 3 client-to-server communication modes: synchronous, asynchronous, and interactive.
Synchronous/Asynchronous communication
Synchronous mode is usually the communication mode of choice. A client sends a request and then receives a response. Servers can handle a new request after the previous request process is complete.
Services are requested by tpcall() and tpacall(). The transmit/receive buffer must be allocated by tpalloc() before data is transmitted. The service routine on the server side is completed by tpreturn() or tpforward().
In synchronous mode, a client issues a request to the server by calling tpcall() and waits for the response from the server in the blocking status.
In asynchronous mode, a client issues a request to the server by calling tpcall(). The client conducts other tasks without waiting for the response from the server. When the client is ready to receive the response from the server, the client calls tpgetrply() and receives the response from the server.
Interactive communication
Unlike synchronous or asynchronous mode, server programs must be developed only with interactive service functions. Interactive mode is rarely used because of its long connection maintenance time.
Service requests are initialized by tpconnect(). Data is sent by tpsend() and received by tprecv(). The transmit/receive buffer must be allocated by tpalloc() before data is sent.
Interactive communication cannot use tpforward().
In synchronous mode, a client requests a service and waits for a response. A client waits for the response in the blocking status.
The following is how client/server programs act in synchronous mode.
For more information on functions related to synchronous communication, refer to "9.3. Synchronous Communication" or "Tmax Reference Guide".
In asynchronous mode, a client requests a service and conducts other tasks without waiting for the response. A client can choose when to receive the response. A client can perform other tasks after sending a request because tpacall() immediately returns after it is called. But, tpgetrply(), which is called to receive a response, waits in the blocking status until the response arrives or timeout occurs.
The following is how client/server programs act in asynchronous mode.
For more information on functions related to asynchronous communication, refer to "9.4. Asynchronous Communication" or "Tmax Reference Guide".
Interactive communication is half-duplex communication between client and server. When a client initially connects to a server, communication control is set. The side with control can send a message while the other side can receive a message. The side with control can relinquish it to other side at anytime. Control is managed by using a flag from the side with control. The other side learns of controls changes through an event value.
The following is the process of passing communication control and disconnecting a connection.
In interactive mode, tpconnect() is used to make a connection, tpsend() is used to send data, and tprecv() is used to receive data. To send data, connection control, which operates by setting a flag value in tpconnect() and tpsend(), is required.
The following is how client/server programs act in interactive mode.
Interactive communication is initiated by calling tpconnect(), which selectively sends data to services and determines which program holds control. If tpconnect() executes successfully, it returns the connection descriptor (cd), which distinguishes message transmissions/receptions from other connections.
Interactive communication is used when additional information is required depending on context. However, compared to other communication modes, an interactive connection stays connected for a long period of time: from the point of connection (tpconnect()) to the point of disconnection (tpdiscon() or tpreturn()). Synchronous/asynchronous communication is recommended because an interactive connection has greater network load.
tpreturn() is generally called in the server to terminate an interactive communication. In this case, the receiving side receives both the data and the TPEV_SVCSUCC event. If the control side calls tpdiscon(), interactive communication is forcibly terminated. When the function is called, data being transmitted may be lost and transactions being processed are rolled back.
Only the program that has communication control can give the control to the counterpart using the TPRECVONLY flag in tpsend(). The counterpart receives data and the TPEV_SENDONLY event and takes control.
To pass the control to the counterpart, set the flags parameter to TPRECVONLY and call tpconnect() or tpsend(). The TPEV_SENDONLY event occurs to the counterpart to let the counterpart know control was received. After control is passed, data can be sent by calling tpsend().
Like synchronous or asynchronous communication, interactive mode uses buffers, which must be allocated in advance by tpalloc(). All buffers used in Tmax communication must be allocated by tpalloc().
For more information on functions related to interactive communication, refer to "9.5. Interactive Communication" or "Tmax Reference Guide".
The following lists the five events of interactive communication:
Event | Receiving Function | Description |
---|---|---|
TPEV_SENDONLY (0x0020) | tprecv() | Indicates the location of the connection control. |
TPEV_DISCONIMM (0x0001) | tesend() tprecv() tpreturn() | Abnormal disconnection. Occurs when tpdiscon() is called or tpreturn() is called while sub-services are still open. |
TPEV_SVCERR (0x0002) | tpsend() tprecv() | Service function error. Occurs when tpreturn() is called by a party that does not have control of the connection or when the argument of tpreturn() is valid but an error is generated. |
TPEV_SVCFAIL (0x0004) | tpsend() tprecv() | Service function failed. Occurs when tpreturn() is called by a party that does not have control of the connection or tpreturn() is called with its flags set to TPFAIL or TPEXIT. |
TPEV_SVCSUCC (0x0008) | tprecv() | Service function successfully completed. tpreturn() is called with the flag set to TPSUCCES. |
For more information about functions, refer to "Tmax Reference Guide".