UDP socket non-blocking
Posted: Sun Jul 08, 2018 12:16 pm
Hi
I am trying to use a UDP socket to both send and receive to another device. The port is known at the outset but the IP of the remote device is not.
My code sort of works in that if I send to the esp32 I can see what I sent on the uart output,, and an 'ACK' is received back from the esp32.
But I can't send correctly as the UDP socket blocks until I send something to it again. So I would have to keep sending something to the esp32 to get my data back.
When I set the dataReady to true nothing is sent until I send it something then I will get the ACK back and my test data.. Then nothing til I send again
I have tried setting the socket to non-blocking but I can't get that to works
int err = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*) &read_timeout, sizeof read_timeout);
also tried
int err = setsockopt(s, IPPROTO_UDP, SO_RCVTIMEO, (char*) &read_timeout, sizeof read_timeout);
This is probably something stupid but can't see it at the moment.
help would be much appreciated.
Full UDP-rec.c is attached
Thanks
Spooney
I am trying to use a UDP socket to both send and receive to another device. The port is known at the outset but the IP of the remote device is not.
My code sort of works in that if I send to the esp32 I can see what I sent on the uart output,, and an 'ACK' is received back from the esp32.
But I can't send correctly as the UDP socket blocks until I send something to it again. So I would have to keep sending something to the esp32 to get my data back.
When I set the dataReady to true nothing is sent until I send it something then I will get the ACK back and my test data.. Then nothing til I send again
I have tried setting the socket to non-blocking but I can't get that to works
int err = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*) &read_timeout, sizeof read_timeout);
also tried
int err = setsockopt(s, IPPROTO_UDP, SO_RCVTIMEO, (char*) &read_timeout, sizeof read_timeout);
This is probably something stupid but can't see it at the moment.
help would be much appreciated.
Full UDP-rec.c is attached
Thanks
Spooney