UDP Send and Receive

Hi all,

I haven’t had too much luck with responses in this forum, but I really need some help on this one.

Im trying to send and receive over UDP and I have looked at the echo example and the UDP stuff posted in the FAQ on rabbit. I have successfully received over UDP but cannot send. My code relating to the UDP looks like:

#define TCPCONFIG 1
#define DISABLE_TCP // Not using TCP
#define LOCAL_PORT 54321
#define REMOTE_PORT 12345

if(sockcheck!=0){printf("Socket init failed
if(!udp_extopen(&sock, IF_ANY, LOCAL_PORT, -1, 0, udp_readf, 0,0)) {
printf("udp_extopen failed!

  just=udp_sendto(&sock,SENDUDPARRAY,sizeof(SENDUDPARRAY), -1, REMOTE_PORT);
  printf("Send status %d


But the send returns -1 every time. Any idea as to whats wrong?

Thanks in advance.

Looks like you’re sending to a remote host address of -1. Sendto needs an IP address of a machine as its 4th argument. If you know the IP you want to send to, just replace the -1 with the inet_addr() conversion of the IP address dotted quad string.

If your ultimate goal is to respond to an incoming message, then the structure filled out by udp_readf() will contain both the remote IP and port for an incoming message. It’s usually better to use those values rather than force a fixed IP and Port, even if your control network is closed and fixed.