UDPSocketRecv

Attempts to receive packets sent to a socket's source port.

Syntax

UDPSocketRecv( BytesReceived, SocketID, InDatagram, InDatagramLen, RemoteIPAdd, RemotePort, Timeout [optional] )

Remarks

UDPSocketRecv() attempts to receive packets sent to a sockets source port.

Parameters

BytesReceived

Number of bytes received (>= 0 since it is possible to receive a 0 length datagram). If -1, no data has been received (if a timeout was specified this means we timed out). If < -1, an error occurred. The values that can be returned are:

Code Description
>=0 Received a datagram with a payload of this many bytes. (It is possible to receive a zero-length UDP datagram.)
-1 Did not receive a datagram, even after potentially waiting if a timeout was set.
-2 Socket not initialized or was closed. (The only way this will be closed is if you call UDPSocketClose.)
-4 Invalid InDatagramLen (negative or greater than the size of the buffer)

-6

Invalid SocketID.

Type: Variable of type Long

SocketID

Socket ID returned from a call to UDPSocketOpen().

Type: Constant or Variable of type Long

InDatagram

Variable in which to store the datagram payload.

InDatagramLen

The size of InDatagram (or how many bytes you wish to be stored). If this parameter is 0, all of the variable's memory will be used.

Type: Variable of Type Long

RemoteIPAddr

IP address of the remote device that sent this datagram (can be passed to UDPSocketSend() to send a datagram to this device).

Type: Constant or Variable of Type String

RemotePort

Port of the remote device that sent this datagram (can be passed to UDPSocketSend() to send a datagram to this device).

Type: Constant or Variable of Type Long

Optional Parameters

Timeout

Timeout in milliseconds to wait for an incoming datagram (if one has not already been received). If 0 (or not specified), we will not wait at all. If there are no datagrams that have been received at the time of calling this instruction or we time out while waiting for incoming packets, -1 is written to the BytesReceived parameter. If this parameter is less than 0, this call will block execution (in its sequence) until a packet comes in or an error occurs. Do not use this functionality when in a scan, since theoretically this could block execution forever (if no packets come in) and cause skipped scans. It is recommended to put this instruction in a scan and periodically check it instead of using this blocking functionality, as datalogger operation is optimized internally by using scans (using the block execution functionality can be less efficient since the datalogger is constantly polling for input).

Type: Constant or Variable of Type Long