QT UDP Multicast (traversal)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.