OPEN.SOCKET()

Top  Previous  Next

 

The OPEN.SOCKET() function opens a data socket for an outgoing connection.

 

 

Format

 

OPEN.SOCKET(addr, port, flags)

 

where

 

addris the address of the system to which a connection is to be established. This may be an IP address or a host name.

 

portis the port number on which the connection is to be established.

 

flagsis a value determining the mode of operation of the socket, formed by adding the values of tokens defined in the SYSCOM KEYS.H record. The flags available in this release are:
SKT$BLOCKINGSets the default mode of data transfer as blocking.
SKT$NON.BLOCKINGSets the default mode of data transfer as non-blocking.

 

 

The OPEN.SOCKET() function opens a connection to the server with the given address and port number.

 

If the action is successful, the function returns a socket variable that can be used to read and write data using the READ.SOCKET() and WRITE.SOCKET() functions. The  STATUS()function will return zero.

 

If the socket cannot be opened, the STATUS() function will return an error code that can be used to determine the cause of the error.

 

 

Example

 

SKT = OPEN.SOCKET("193.118.13.14", 3000, SKT$BLOCKING)

IF STATUS() THEN STOP 'Cannot open socket'

N = WRITE.SOCKET(SKT, DATA, 0, 0)

CLOSE.SOCKET SKT

 

This program fragment opens a connection to port 3000 of IP address 193.118.13.14, sends the data in DATA and then closes the socket.

 

 

See also:

ACCEPT.SOCKET.CONNECTION, CLOSE.SOCKET, CREATE.SERVER.SOCKET(), READ.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO(), WRITE.SOCKET()