ACCEPT.SOCKET.CONNECTION() |
![]() ![]() ![]() |
The ACCEPT.SOCKET.CONNECTION() function opens a data socket on a server to handle an incoming connection.
Format
ACCEPT.SOCKET.CONNECTION(srvr.skt, timeout)
where
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.
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.
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 from this connection and then closes the sockets.
See also: CLOSE.SOCKET, CREATE.SERVER.SOCKET(), OPEN.SOCKET(), READ.SOCKET(), SERVER.ADDR(), SET.SOCKET.MODE(), SOCKET.INFO(), WRITE.SOCKET() |