Understanding of UDP multicast

Source: Internet
Author: User
UDP multicast can be used to broadcast data in the intarnet or Internet datagram mode (multicast over the Internet requires the router to support IGMP (Internet gateway management protocol, this Protocol appears after the IP address appears to support multicast )). compared with broadcasts that consume extremely bandwidth (broadcast can only be broadcast within the Intranet), UDP multicast has been greatly optimized, and only terminals are added to a broadcast group, only UDP multicast data can be accepted by him.
UDP multicast adopts the connectionless and datagram connection mode, so it is unreliable. that is, the order in which the data can arrive at the receiver and the data arrival is not guaranteed. however, because UDP does not need to ensure data reliability, the transmission speed of all data is very fast.
1. multicast "root"
In terms of concept, multicast is divided into two parts: the control part and the data part. The control part determines the way in which multicast objects are organized. The data part determines the data transmission mode.
The control layer can be "root" or "Root-free. For the control layer with a root, there is a root and several leaf.
Root is responsible for managing this multicast group. Only one leaf can be invited to a multicast group (ATM is a typical example with root control ). For the rootless control layer, there is no root, only a few leaf.
Each leaf can join a multicast group by itself (IP is a typical example of rootless Control)
The data layer also has two scenarios: "root" and "Root-less. For the root data layer, the data sent from the root can reach each leaf, while the data sent from the leaf can only reach the root. for the rootless data layer, the data sent by each leaf can reach each leaf (or even its own) in the multicast group ). Each leaf can also accept any data packet from a multicast group.
Ii. IP multicast address
For IP multicast communication, a special multicast address is required. The IP multicast address is a group of D-class IP addresses ranging from 224.0.0.0.
To
239.00000000255. Many other addresses are reserved for special purposes. 224.0.0.0 to 224.0.0.255 address is not recommended, because they are mostly maintained for special purposes (such as IGMP Protocol)
Iii. IGMP Protocol
IGMP (Internet gateway Management Protocol) is the basis for IP multicast. after the emergence of the IP protocol, IGMP is generated to support multicast. What IGMP does is to tell the vro that someone in the subnet of the vro is interested in the data sent to a multicast group, so that when the data of the multicast group arrives at the end, the router will not abandon it, but send it to all interested customers. If multicast communication is required between A and B in different subnets, all routers of A and B must support the IGMP protocol. Otherwise, B cannot communicate with each other.
When an application is added to a multicast group, an IGMP addition command is sent to all vrouters In the subnet, tell him that someone in the subnet is interested in the data sent to a multicast group. the router also regularly sends a query message to all terminals in the subnet to check whether there are still people interested in the data of a multicast group. If any, the terminal will respond to an IGMP message, and the router will continue to forward the data of this multicast group. If no one responds to this message, the vro considers that there are no terminals interested in the multicast group data and will not forward data about this multicast group. In the second version of IGMP, after a terminal launches a multicast group, it will send a publish message to the router, the router also uses this message to determine whether to continue forwarding data about the multicast group (this function is not available in the first version of IGMP). [these tasks are done by the underlying system, you just need to enjoy it]
Iv. Winsock 1 Multicast
For Winsock 1, perform the following steps:
1. Create scoket that supports Datagram
2. Bind the socket to a local port (data will be sent and received through this port in the future)
3. Use setsockopt ip_add_membership to join a multicast group
4. Then, you can use sendto/recvfrom to collect data.
5. Use setsockopt ip_drop_membership to exit a multicast group
6. Disable socket
If you only want to send data to a multicast group, instead of accepting the data, you can directly send data to the multicast group through sendto instead of joining the multicast group.
5. WinSock 2 Multicast
WinSock
2 multicast is implemented mainly through wsajoinleaf (the behavior of wsajoinleaf, the returned value depends on the socket mode, and the implementation architecture of multicast has a great relationship)
The following are the main steps for WinSock 2 Multicast:
1. Establish a socket that supports datagram (use wsasocket to establish a socket. 2. Set Some attributes of multicast)
3. Bind the socket to a local port (through which data will be sent and received later)
4. Add a multicast group through wsajoinleaf
5. send and receive data through sendto/recvfrom
6. Directly close the socket,
7. Exit the multicast group

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.