IT Management

VSE TCP/IP PROGRAMMING

6 Pages

Initialization

The primary unitization call is the INIT-API call. This call establishes the TCP/IP environment for use by the programmer. Lines 1 through 9 of Figure 1 show this call.

Creating a Connection

The first step to establishing a connection is to allocate a “socket.” At a basic level, the SOCKET call allocates storage for use in the conversation. Lines 10 through 19 of Figure 1 show this call. This call will return in EZA-RETCODE a socket “number” that you can use for all following calls. Note that socket numbers start at zero, not one.

After you create the socket, the client program must establish the connection using a CONNECT call. Before this call, the program needs to know the address of the server. The API uses a data area called name to pass this information. The area name contains three fields: family, port, and ipaddress. The family field is always set to +2 to indicate that the connection is to be via IP. The client program must set the port and ipaddress fields prior to calling the API. Lines 20 through 29 of Figure 1 show a sample of this call.

Transferring the Data

To transfer data, the program needs to send a request to the server and then receive the response sent from the server. This can be accomplished using the SEND and RECV calls. Other similar calls can be used, each with slightly different options and capabilities. Lines 30 through 39 and lines 40 through 51 of Figure 2 show valid SEND and RECV calls.

One aspect of TCP/IP communication that many mainframe programmers find confusing is the fact that when data is received, it may not always be complete. This can happen when the amount of data sent exceeds the packet size limits for one of the intermediate segments of the IP communication path between the client and the server. The program must validate the number of bytes received, and when the complete data has not been received, the program must request additional data from the server. Optionally, if the data expected is extremely short (like “GOOD”), the programmer would not have to worry about multiple data receives being required. For simplicity’s sake, the sample assumes that the response is short and does not check the length of the data returned.

6 Pages