Skip to main content
######
Senior II
Aug 8, 2023 1:24 PM UTC
Solved

LWIP Raw API udp_send() Cube MX HAL

Hi,

LWIP: what is the difference between udp_send() and udp_sendto()?

What are the use cases for each? 

The LWIP_RAW_CLIENT ECHO uses udp_send() but also uses udp_connect. Whereas udp_sendto() does not need to connect?

Does anyone have example? 

Thanks

This topic has been closed for replies.
LCE
LCEBest answer
Principal III
Aug 10, 2023 3:22 PM UTC

In both my PTP sources and the UDP echo test I use udp_sendto.

5 replies

LCE
Principal III
Aug 8, 2023 2:33 PM UTC

https://lwip.fandom.com/wiki/Raw/UDP

err_t udp_connect(struct udp_pcb * pcb, struct ip_addr * ipaddr, u16_t port)

Sets the remote end of the pcb. This function does not generate any network traffic, but only set the remote address of the pcb. It binds the pcb to a local address if it is not already bound. It returns ERR_USE if no port is available, ERR_RTE if there is no route to the destination, or ERR_OK. Connecting is only needed when using udp_send(). For unconnected pcbs, udp_sendto() can be used to send to any specified remote address. Connected pcbs only receive data from the connected remote address, while unconnected pcbs receive datagrams from any remote address.

Sometimes google helps! ;)

######
######Author
Senior II
Aug 8, 2023 3:46 PM UTC

Thanks. I'd read the documentation. I was really looking for some information explained differently from a different source.

LCE
Principal III
Aug 9, 2023 11:49 AM UTC

Okay, it's basically all in there.

######
######Author
Senior II
Aug 9, 2023 12:22 PM UTC

@LCE which function do you normally use?

LCE
LCEBest answer
Principal III
Aug 10, 2023 3:22 PM UTC

In both my PTP sources and the UDP echo test I use udp_sendto.