Home  Contents

rawio:recvfrom

Rawio Core4 Lua Event System

SYNOPSIS

data, host, port = handle:recvfrom([flags, [maxlen, [maxwait]]])

DESCRIPTION

This call works only on UDP sockets.

Receives data from a socket in the same way as rawio:read() would do. It additionally supports the passing of flags and returns the peer address where the received data has originated.

The optional flags parameter is not supported currently, and should be nil if passed at all.

Reads at most maxlen bytes of data from the socket. The default for maxlen is 4096 bytes. If the socket has a bigger packet pending, the remainder of the packet is discarded.

In non blocking mode, returns immediately if no data is available. In blocking mode, the call will wait for data to become available before it returns.

If the optional timeout value is given, the call will wait for this amount of milliseconds for data before it fails. This applies to both blocking and non-blocking mode.

RETURN VALUE

On success, returns a string with the data that was read and also 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