How to broadcast in java network

白昼怎懂夜的黑 提交于 2019-12-04 04:38:42

To broadcast data packets, send them to the broadcast address of the given subnet (the last address of the subnet). The IP 255.255.255.255 is the broadcast address for the zero network.

A special definition exists for the IP broadcast address 255.255.255.255. It is the broadcast address of the zero network or 0.0.0.0, which in Internet Protocol standards stands for this network, i.e. the local network. Transmission to this address is limited by definition, in that it is never forwarded by the routers connecting the local network to the Internet.

Broadcast address

So to broadcast to your current network, send the packets to 255.255.255.255.

Do not confuse terms.

Broadcast is usually used for UDP. UDP is unreliable in the sense that it does not check if all of the packets are received by the clients. Opening a lot of TCP connections to a lot of clients is not broadcast.

To have your clients listen to a port, you need to use ServerSocket and read it.

I recommend that you use PubSubHubbub or a similar protocol. Basically, you would have a "hub" to which you send the notification that you want to have "broadcasted". Each of the nodes subscribes to the topic, by providing a URL that the hub can invoke when new data has arrived. When the "hub" receives this broadcast, the hub contacts each subscription URL to let the node know there is new data.

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