READ.SOCKET() |
![]() ![]() ![]() |
The READ.SOCKET() function reads data from a socket opened with ACCEPT.SOCKET.CONNECTION() or OPEN.SOCKET().
Format
READ.SOCKET(skt, max.len, flags, timeout)
where
If neither blocking flag is given, the blocking mode set when the socket was opened is used.
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: ACCEPT.SOCKET.CONNECTION, CLOSE.SOCKET, CREATE.SERVER.SOCKET(), OPEN.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO(), WRITE.SOCKET() |