READ.SOCKET()

READ.SOCKET()

Top  Previous  Next

 

The READ.SOCKET() function reads data from a socket.

 

 

Format

 

READ.SOCKET(skt, max.len, flags, timeout)

 

where

 

sktis the socket variable returned by ACCEPT.SOCKET.CONNECTION() (stream connections), CREATE.SERVER.SOCKET() (datagram connections) or OPEN.SOCKET().

 

max.lenis the maximum number of bytes to read.

 

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

If neither blocking flag is given, the blocking mode set when the socket was opened is used.

 

timeoutis the timeout period in milliseconds. A value of zero implies no timeout.

 

 

The READ.SOCKET() function returns data read from the specified socket. The STATUS() function returns zero if the action is successful, or a non-zero error code if an error occurs. A timeout will return an error code of ER$TIMEOUT as defined in the SYSCOM ERR.H record.

 

 

Example

 

SRVR.SKT = CREATE.SERVER.SOCKET("", 0)

IF STATUS() THEN STOP 'Cannot initialise server socket'

SKT = ACCEPT.SOCKET.CONNECTION(SRVR.SKT, 0)

IF STATUS() THEN STOP 'Error accepting connection'

DATA = READ.SOCKET(SKT, 100, SKT$BLOCKING, 0)

CLOSE.SOCKET SKT

CLOSE.SOCKET SRVR.SKT

 

This program fragment creates a server socket, waits for an incoming connection, reads a single data packet of up to 100 bytes from this connection and then closes the sockets. The timeout value of 0 in the READ.SOCKET() call specifies that no timeout is to be used.

 

 

See also:

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