This topic contains information that you might find helpful when you use REXX sockets.
Throughout the documentation, REXX socket API commands and constants are capitalized when they are used in descriptive text. For example, the LISTEN command places a socket descriptor in passive mode.
Throughout the documentation, REXX socket API commands and constants are enclosed in quotation marks (") when they are used in code examples, for example, src = socket("ACCEPT",sockfd);.
Although the use of quotation marks is optional, consider using quotation marks to prevent programming errors. Using quotation marks forces the socket function to use string literals rather than REXX variables. When REXX encounters an uninitialized variable, it initializes that variable with the name of the variable. The command socket(ACCEPT,sockid) is valid because the uninitialized variable ACCEPT is initialized to the character string ACCEPT. However, if the program initializes the ACCEPT variable with a value other than the character string ACCEPT, the socket function fails.
l_string1 = "This is a string split between",
"two lines.";
src = socket("GETADDRINFO","CHILE",,
23,"AI_CANONNAMEOK");
In this example, the first comma after the parameter "CHILE" indicates the end of the parameter. The second comma indicates that the REXX statement continues on the next line.
To avoid problems, an application should check the return code of a socket command after each socket call. The examples in this topic do not always follow this recommendation. The examples are intended to show how to issue the socket command.
parse var l_retcode src remainder;
if src = 0 then do
/* DO SOME STUFF */
end;
else do
/* Process the error */
end;
To use the socket commands provided by the REXX socket function, a socket set must be active. To allocate a socket set, use the INITIALIZE socket command. The INITIALIZE command creates a socket set and can support multiple socket calls. The subtaskid value identifies the socket set and usually corresponds to the application name. The service value indicates the TCP/IP stack name to form an affinity with.
A socket can be in blocking or nonblocking mode. In blocking mode, commands such as SEND and RECV block the caller until either the operation is completed successfully or an error occurs. In nonblocking mode, the caller is not blocked, but the operation ends immediately with either the 35 EWOULDBLOCK or 36 EINPROGRESS return code. Use the FCNTL or IOCTL commands to switch the socket between blocking and nonblocking modes.
When a socket is in nonblocking mode, you can use the SELECT command to monitor the socket for one or more socket events. The socket can be monitored for events that indicate that the socket is ready for writing or reading, or whether an exception has occurred.
If the application uses the GIVESOCKET and TAKESOCKET commands to transfer a socket from a parent program to a subtask, both the parent and subtask must agree on a mechanism for exchanging the client ID and the socket descriptor. The parent program can use the SELECT command to monitor when the subtask takes the socket. After the subtask takes the socket, the parent then can close the socket that was given.
The socket options SO_ASCII and SO_EBCDIC identify the socket data type for use by the REXX RXSOCKET program. Setting the SO_EBCDIC option to ON has no effect, and setting the SO_ASCII option to ON causes all incoming data on the socket to be translated from ASCII to EBCDIC and all outgoing data on the socket to be translated from EBCDIC to ASCII.