What is the 'wildcard address' In the context of UDP Broadcasts?

假如想象 提交于 2020-01-03 02:04:56

问题


Referring to the Java 6 API docs for the DatagramSocket class:

UDP broadcasts sends are always enabled on a DatagramSocket. In order to receive broadcast packets a DatagramSocket should be bound to the wildcard address. In some implementations, broadcast packets may also be received when a DatagramSocket is bound to a more specific address.

Could someone tell me what the 'wildcard address' is? And is the following valid for listening for UDP broadcasts:

MulticastSocket socket = new MulticastSocket(new InetSocketAddress(InetAddress.getByName("0.0.0.0"),4445);

回答1:


The wildcard address is 0.0.0.0. Not to be confused with the broadcast-to-all-subnets address, which is 255.255.255.255. It is more correctly called the 'any' address, after INADDR_ANY.

In Java it is most easily used by supplying null as a bind-address, or omitting the parameter altogether, e.g. new InetSocketAddress(null, 0) or new InetSocketAddress(0) respectively. In other words it is the default when binding, and therefore implicitly 'good practice'.



来源:https://stackoverflow.com/questions/14733183/what-is-the-wildcard-address-in-the-context-of-udp-broadcasts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!