OPEN.SOCKET()

OPEN.SOCKET()

Top  Previous  Next

 

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

 

 

Format

 

OPEN.SOCKET(addr, port, flags {, timeout})

 

where

 

addris the address of the system to which a connection is to be established. This may be an IPV4 or IPV6 address or a host name. Use of IPV6 must be enabled using the IPV6 configuration parameter.

 

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

 

flagsis a flag value formed from the additive values below. The token values are defined in the SYSCOM KEYS.H include record.

Socket type, one of:

SKT$STREAMA stream connection (default)
SKT$DGRMA datagram type connection
SKT$USTREAMA named Unix domain socket connection

Protocol, one of:

SKT$TCPTransmission Control Protocol (default)
SKT$UDPUser Datagram Protocol

Blocking mode, one of:

SKT$BLOCKINGSets the default mode of data transfer as blocking.
SKT$NON.BLOCKINGSets the default mode of data transfer as non-blocking.

 

timeoutis the maximum number of seconds to wait for connection.        

 

 

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

 

For Unix domain sockets, the addr argument is the pathname of the socket connection and the port and timeout arguments are ignored.

 

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, possibly in conjunction with OS.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:

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