A client application uses the CONNECT command to establish a connection between a local socket and a remote socket.
The command supports both blocking and nonblocking sockets. When the socket is in blocking mode, the function does not return until a connection with the remote peer is established or until an error is received. When the socket is in nonblocking mode, the function returns immediately with either the 36 EINPROGRESS return code or an error.
The return code can be 0, a REXX socket API error number, or the REXX TCP/IP error number that is set by the socket command. The return code 0 indicates that the requested socket command was completed successfully.
See Socket call error return codes for additional information about the numeric error codes that are returned by this command.
int connect(int socket, struct sockaddr *address, int address_len);
/* REXX EZARXR03 */
/*
* This sample demonstrates the use of the INITIALIZE, SOCKET,
* CONNECT, GETSOCKNAME, SEND, RECV, CLOSE and TERMINATE
* socket commands.
*
* The program will INITIALIZE a socket set and create a STREAM
* socket. If successful an attempt will be made to connect to
* port 7 using the loopback address and 7 bytes of data will be
* sent. The program will then wait for the data to be echoed
* back.
*
* Port 7 is the well known port for the ECHO server. The ECHO
* Server for the z/OS Communication Server is the MISCSERV. For
* Information on setting up the MISCSERV see the IP Configuration
* Reference.
*
* The example EZARXR01 can be modified to echo data back by adding
* a SEND command after the RECV command. This is left as an exercise.
*
* GUIDELINE: It is generally recommended that a program loop around
* the RECV command to ensure that all data is read off
* the socket.
*/
src = socket("INITIALIZE","MYSET01");
if perror(src,"INITIALIZE") = 0 then do
src = socket("SOCKET","AF_INET","STREAM");
if perror(src,"SOCKET") = 0 then do
l_socketid = WORD(src,2);
l_RMTname = "AF_INET 7 127.0.0.1";
src = socket("CONNECT",l_socketid,l_RMTname);
if perror(src,"CONNECT") = 0 then do
src = socket("GETSOCKNAME",l_socketid);
if perror(src,"GETSOCKNAME") = 0 then do
l_LOCname = SUBWORD(src,2);
Say "The local socket name is: "l_LOCName;
src = socket("SEND",l_socketid,"*******");
if perror(src,"SEND") = 0 then do
src = socket("RECV",l_socketid);
if perror(src,"RECV") = 0 then
Say "Echoed data: " word(src,3);
end; /* SEND*/
end; /* GETSOCKNAME*/
end; /* CONNECT */
end; /* SOCKET */
src = socket("CLOSE",l_socketid);
src = perror(src,"CLOSE");
end; /* INITIALIZE */
src = socket("TERMINATE","MYSET01");
src = perror(src,"TERMINATE");
exit 0;
/* This routine returns -1 if the first word if arg 1 is not zero */
perror: if word(arg(1),1) = 0 then return 0; else
Say arg(2) "Error : "arg(1);
return -1;