Function to receive an UDP message with the possibility to know the port and IP address of the transmitter.
The function can be used for both client and server communications. Specifically, the server uses the rPort and rIp information returned by this function to send an eventual response to the client station via the udp_send_to().
Syntax |
i32 udp_recv_from (i32 idx, buff, i32 buffLen, u32 rPort, u32 rIp) |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
idx |
Number of the handler of the UDP communication |
||||||||||
buff |
Generic buffer intended to contain the received data packet. It can be a string variable, a struct_p (packed structure), or an array of struct_p. In the case of struct_p, the variable must be declared global |
||||||||||
buffLen |
Maximum number of bytes to receive |
||||||||||
rPort |
Number of the remote port from which data was received (its contents are written by this function) |
||||||||||
rIp |
Remote IP address from which the data was received (its contents are written by this function; it is not necessary to specify it before the call) |
||||||||||
Result |
Returns:
To see some returned errors more specifically, see Returned Errors Table |
||||||||||
Validity |
Rule, Task |
||||||||||
Note |
A place must always be reserved at the head of the receive data buffer for a u32, which contains the identifier msgId. This identifier must be retransmitted without modification (via the udp_send_to() function) at the head of the buffer containing the response. Without this identifier, a client using the udp_send_notify() and udp_recv_notify() functions will not be able to identify the response as correct |
For a concrete example see in the RDE environment: Workspace -> Specials -> Examples Library.