Reputation: 325
I have a UDP server in C based on libuv
, we have a :
bind()
to port 9930Now, when i send request (src_port:A
and dest_port:9930
) to the UDP server , the server responds with a UDP packet with src_port:B
and dest_port:A
. I want B to be equal to 9930.
I went through some articles online and set UV_UDP_REUSEADDR
flag in uv_udp_bind()
for both the main thread and in the 4 worker thread. But, now the udp server doesn't always accept the request, not even the receive callbacks are invoked. It does sometimes and for these cases the flow is proper with port B=9930
.
Upvotes: 0
Views: 516
Reputation: 136208
Now, when i send request (src_port:A and dest_port:9930) to the UDP server , the server responds with a UDP packet with src_port:B and dest_port:A. I want B to be equal to 9930.
The server must respond from a socket bound to port 9930
then. E.g. respond from the very same socket that received the request.
Also, the worker threads can share the same one socket the main thread opened. When multiple threads receive on the same UDP socket, only one of them gets the datagram. It is also safe for multiple threads to send on the same UDP socket.
Upvotes: 1