| %CLOSE | Index Level | %CREAT |
| Syntax | code = %CONNECT( socket, addr.family, host, port ) |
| Category | BASIC |
| Type | C Function |
| 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 FlashBASIC C function '%socket'. 'addr.family' 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. |
| Options | |
| See Also | CFUNCTION %SOCKET %CLOSE |
| Example |
cfunction socket.builtin
include dm,bp,unix.h socket.h * Create a socket fd=%socket(AF$INET,SOCKET$STREAM,0) * Connect to the distant host if %connect(fd,AF$INET,"prod",1024)<0 then crt 'Connect failed'; stop end * Write data to it msg="CONNECTED" %write(fd,msg,len(msg)) * Terminate connection %close(fd) |
| Warnings | Sockets are a BSD extension, which may not be availableon all Unix platforms. |
| Compatibility | D3/Unix |
| %CLOSE | Index Level | %CREAT |