SOCKET_ACCEPT Function

Waits for a connection on a socket. This routine blocks until a connection is received or the Timeout value is reached.

Usage

connection = SOCKET_ACCEPT(socket) 

Input Parameters

socket—A socket descriptor (returned from the SOCKET_INIT Function ).

Keywords

Timeout—Length of time to wait for a client connection, in milliseconds. Timeout=0 will cause SOCKET_ACCEPT to timeout immediately if a connection is not available. Default: Timeout is off and SOCKET_ACCEPT blocks until a connection is established.

Returned Value

connection—The socket descriptor on which the connection is made. A return value of –1 indicates a timeout occurred. A return value of –2 indicates a system error.

Discussion

This routine blocks the currently running application until a socket connection is received from the client or the Timeout value is reached.

The input parameter, socket, must be a value returned from either SOCKET_INIT or SOCKET CONNECT.

SOCKET_ACCEPT listens on the port represented by the input parameter, socket. Immediately upon making a connection, a new socket is assigned to handle the communication flow. This new socket is represented by the returned value connection.

Example

The following simple server program uses SOCKET_ACCEPT to listen for client connections. This program simply prints a string sent from the client.

PRO SERVER
   port = 1500
   socket = SOCKET_INIT(port)
   connection = SOCKET_ACCEPT(socket)
   data = BYTARR(15)
   nbytes = SOCKET_READ(connection,data)
   PRINT, 'SERVER received: ', STRING(data)
   SOCKET_CLOSE, connection
   SOCKET_CLOSE, socket 
END

See Also

SOCKET_INIT

For more detailed information on using the socket routines, see the PV‑WAVE Application Developer’s Guide.