Is it possible to create a Java UDP socket to listen on all addresses?

I would like to have one DatagramSocket to listen to both unicast and broadcast messages. Is it possible?

+3
source share
2 answers

Broadcasting is, by definition, a transmission function.

If your UDP socket listens on a specific port and is bound to INADDR_ANY(aka 0.0.0.0), it will receive all packets sent to this port, regardless of whether they were sent to the local IP addresses of a specific computer (i.e., unicast) or to The broadcast address of the local subnet.

+6
source

I think that if you specify the address 0.0.0.0, it will do the job.

+1
source

All Articles