The ACCEPT.SOCKET.CONNECTION() function opens a data socket on a server to handle an incoming stream connection.
The ACCEPT.SOCKET.CONNECTION() function waits for an incoming connection on a previously created server socket and returns a new data socket for this connection.
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. The socket will initially be in blocking mode. This can be modified by use of the SET.SOCKET.MODE() function.
If the socket cannot be opened, the STATUS() function will return an error code that can be used to identify the cause of the error. If no connection arrives before the timeout period expires, the error code will be ER$TIMEOUT as defined in the SYSCOM ERR.H include record.
SRVR.SKT = CREATE.SERVER.SOCKET("", 4000, SKT$STREAM + SKT$TCP)
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)
This program fragment creates a server socket, waits for an incoming connection, reads a single data packet from this connection and then closes the sockets.