Using QUdpSocket to send datagrams

蓝咒 提交于 2019-12-05 20:53:10

You need something like this

QHostAddress myBroadcastAddress = QHostAddress("192.168.255.255");
udpSocket->writeDatagram(datagram.data(),datagram.size(), myBroadcastAddress , 45454 )

This will send udp broadcast packets.

The broadcast address of a subnet is always the highest address in the subnet. In your case:

adapter1: address 192.168.1.104 subnet mask 255.255.255.0 broadcast: 192.168.1.255

adapter2: address 192.168.56.1 subnet mask 255.255.255.0 broadcast: 192.168.56.255

So you need both the address of the adapter you want to broadcast on and the subnet mask to find the correct broadcast address.

If you use adapter address and subnet mask to calculate the broadcast address this should work for IPv4 networks.

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