Home  Contents

rawio:accept

Rawio Core4 Lua Event System

SYNOPSIS

peer_handle, host, port = server_handle:accept()

DESCRIPTION

This function is used with TCP sockets that have been set up to accept incoming connections using rawio:bind() and rawio:listen().

The call takes the first pending connection from the incoming queue and creates a new socket handle that is connected to the peer which requested the connection. The new socket is in the connected state, while the listening socket keeps on listening.

In blocking mode, if no connections are pending, the call waits until a new connection arrives. In non-blocking mode, an error is returned in that case.

To process incoming connections using an event loop, set the socket to non-blocking mode and add an event handler that waits for the socket to become readable using event:add(). When the event callback is triggered, the socket is ready for another call to rawio:accept().

RETURN VALUE

On success, returns a new socket handle, a string containing the IP address of the peer that has connected and the port number at the peer machine that has connected. On failure, returns nil. In case of an error, the error can be retrieved using rawio:lastError().

SEE ALSO