basic.%connect C Function/BASIC Program


Command basic.%connect C Function/BASIC Program
Applicable release versions: AP/Unix
Category BASIC Program (486)
Description requests a connection between two sockets.

To compile successfully, the statement 'cfunction socket.builtin' must be included in the source code.

'socket' Is the file descriptor of the local socket returned by a previous call to the Pick/BASIC C function '%socket'.

'' Specifies the addressing scheme used by the protocol. This field must match the address family used when creating the socket. Valid values are defined in the include: 'dm,bp,unix.h socket.h'.

'host' Destination host name. This string must be known to the local network manager (normally defined in the '/etc/hosts/ Unix file). Internally, this string calls the BSD function 'gethostbyname' to read the '/etc/hosts' file.

'port' Port number on the distant host. Legal value for this field depends on the protocol. On TCP/IP, for example, valid port numbers are from 1024 to 32767.

Upon successful completion, a value of 0 is returned in 'code'. In case of error, a value of -1 is returned and the function 'system(0)' is set to the value of 'errno'.

The connection is closed when the socket is closed.
Syntax code=%connect( socket,, host, port )
cfunction socket.builtin
include dm,bp,unix.h socket.h

* Create a socket

* Connect to the distant host        
if %connect(fd,AF$INET,"prod",1024)<0 then
  crt 'Connect failed'; stop

* Write data to it

* Terminate connection
Related basic.cfunction