ACCEPT.SOCKET.CONNECTION()

ACCEPT.SOCKET.CONNECTION()

Top  Previous  Next

 

The ACCEPT.SOCKET.CONNECTION() function opens a data socket on a server to handle an incoming stream connection.

 

 

Format

 

ACCEPT.SOCKET.CONNECTION(srvr.skt, timeout)

 

where

 

srvr.sktis the server socket created by an earlier use of CREATE.SERVER.SOCKET.

 

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

 

 

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.

 

 

Example

 

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)

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:

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