views:

1123

answers:

2

I would like to have a single DatagramSocket to listen for both unicast and broadcast messages. Is this possible?

A: 

I think if you set the address to 0.0.0.0, it'll do the work.

Mehrdad Afshari
+4  A: 

Broadcasting is, by definition, a transmission function.

If your UDP socket is listening on a particular port and bound to INADDR_ANY (aka 0.0.0.0) then it'll receive all packets sent to that port, regardless of whether they were sent to the local machine's specific IP addresses (i.e. unicast), or to the local subnet's broadcast address.

Alnitak