UDP receive datagram and answer it

Hi, I"m using UDP for years now in several background apps for logging. Works perfect.

Question: Is it possible to send an answer directly to the client who was sending a datagram?

yes, you can just write a datagram:
to the IP Address of the sender and the port where the sender is listening on.

1 Like

Indeed! Within the socket directly a new datagram is working.

But, because UDP is connectionless, how long will routers keep this ‘route’ open?

There is no route to keep open. If the routers are configured correctly, the UDP broadcast should propagate.

If you want something more reliable, you could use a TCPSocket for the confirmation callback.

1 Like

Basicly as long as you have control (bound to) the port that receives you are ok.

Sending works like:
If you are not bound to a port for sending, set port to 0 and one will be used for outgoing packets.
As long as you send to an ip-address only that ip will receive it.
As long as you send to a broadcast address (ending at 255 mostly) all the upd listeners on the same port (you sent it to) will receive the package.

1 Like