Previous Topic: &SOCKET CLOSE

Next Topic: &SOCKET GETHOSTBYADDR


&SOCKET CONNECT

Connects a process to a server.

&SOCKET CONNECT 
      { ADDRESS=ip_address | HOSTNAME=host_name } 
        PORT=port_id 
      [ WAIT={ time | 30 } ] 
      [ TYPE={ SYNC | ASYNC }]

CONNECT attempts to establish a connection to the server, at the host specified by IP address or host name on the specified port number.

Operands:

ADDRESS=ip_address

Specifies the IP address of the host.

HOSTNAME=host_name

Specifies the name of the host to which you are connecting.

PORT=port_id

(Mandatory) Specifies the TCP port number that the server is waiting on for client connections. TCP port numbers range from 0 to 65535.

WAIT={ time | 30 }

Specifies the time (in seconds)to wait for the host to respond. The default value is 30 seconds.

TYPE={ SYNC | ASYNC }

Indicates whether this is a synchronous (SYNC) or asynchronous (ASYNC) socket request.

If TYPE=ASYNC is specified, WAIT cannot be specified.

If TYPE=ASYNC is specified, the verb returns control immediately, and a notification message is queued to the dependent environment when CONNECT completes:

N00101 NOTIFY: TCP/IP EVENT: CONNECT RESOURCE: RC=rc RSN=rsn ERR=errno VERRIN=vendor_info ID=new_socket_id **addr/name**

where **addr/name** is set to the destination specified on the CONNECT request (that is, either ADDRESS=ip_address or HOSTNAME=host_name)

Note: ID= is omitted if the CONNECT fails.

Examples: &SOCKET CONNECT

&SOCKET CONNECT ADDRESS=172.24.91.45 PORT=&PRT 
&SOCKET CONNECT HOSTNAME=TESTMVS1 PORT=&PRT

Return Codes:

0

Connect successful

8

Connect failed; see &ZFDBK for reason code, &ZSOCERRN and &ZSOCVERR for further error information.

Notes:

The verb is executed only by the client in client/server applications using TCP sockets.

The &ZSOCID system variable contains the socket number to be used for communications with the server.