http://blog.csdn.net/victoryknight/article/details/7814243 ThemesUDPQtRouters
If the two machines in the LAN are separated from each other, the communication between the two machines cannot be broadcast, but we can switch to the multicast communication to achieve the mutual communication effect.
A server-side
qudpsocket Udp_socket; udp_socket.bind ( qhostaddress::any, Udp_listen_port, QUdpSocket:: Reuseaddresshint); qhostaddress mcast_addr ( "224.0.0.17"); udp_socket.setsocketoption (qabstractsocket::multicastloopbackoption, 0); //prevent native receive udp_socket .joinmulticastgroup (MCAST_ADDR); //This sentence is the key, join the multicast address
At this point, we have completed the binding of the server and joined the work of the multicast group.
Two clients
Mcast_addr ("224.0.0.17"); The multicast address is the same as the server udp_socket. Writedatagram (Datagram, mcast_addr, udp_send_port); Send data to the server (Udp_send_port is the same as the server's listening port)
Http://www.tuicool.com/articles/zUJVBj
QT UDP Multicast (traversal)