IP multicast (also called multicast or multicast) technology allows one or more hosts (Multicast sources) to send a single packet to multiple hosts (once and simultaneously) TCP/IP network technology.
Multicast, as a one-to-multiple-point communication, is one of the effective ways to save network bandwidth.
In Network Audio/Video Broadcast applications, when a node signal needs to be transmitted to multiple nodes, whether it is through repeated point-to-point communication or broadcast, network bandwidth is a serious waste. Only multicast is the best choice. Multicast enables one or more multicast sources to send only data packets to a specific multicast group, and only the host that joins the multicast group can receive data packets.
Currently, IP multicast technology is widely used in network audio/video broadcast, Aod/VOD, network video conferencing, multimedia distance education, and "push" technology (such as stock quotations) and Virtual Reality games.
IP multicast addresses use Class d ip addresses. The address ranges from 224.0.0.0 to 239.255.255.255.
Some examples of retaining IP multicast addresses:
224.0.0.1-all hosts on this subnet.
224.0.0.2-all routers on this subnet.
224.0.0.5-Open Shortest Path First (OSPF)AlgorithmVersion 2nd, designed to reach all OSPF routers on a network.
224.0.0.6-Open Shortest Path Priority Algorithm version 2nd, designed to reach all the routers specified by OSPF on a network.
224.0.0.9-route information protocol (RIP) version 2nd.
224.0.1.1-Network Time Protocol ).
Group Management Protocol (IGMP)
1. Read the acceptor first
The host must be a member of an IP multicast group before receiving IP multicast data.
Code
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. net. Sockets;
Using System. net;
Namespace _ 5. _ 3_ip Multicast
{
Class Program
{
Static Void Main ( String [] ARGs)
{
// 1. Create a set of characters
Socket s = New Socket (addressfamily. InterNetwork, sockettype. dgram, protocoltype. UDP );
S. setsocketoption (socketoptionlevel. socket, socketoptionname. reuseaddress, True );
//2 bind to port 4567
Ipendpoint IPE= NewIpendpoint (IPaddress. Any,4567);
Endpoint EP=(Endpoint) IPE;
S. BIND (EP );
//3 add to multicast group 234.5.6.7
Multicastoption optionvalue= NewMulticastoption (IPaddress. parse ("234.5.6.7"));
S. setsocketoption (socketoptionlevel. IP, socketoptionname. addmembership, optionvalue );
// 4. receive multicast group data
Console. writeline ( " Start receiving data from multicast group 234.5.6.7... " );
Byte [] Buffer = New Byte [ 1024 ];
While ( True )
{
Int Nret = S. receivefrom (buffer, Ref EP );
If (Nret > 0 )
{
String Data = Encoding. Unicode. getstring (buffer, 0 , Nret );
Console. writeline (data );
}
}
}
}
}
2. Sender
To send data to a group, you do not need to add data to that group.
Code
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. net. Sockets;
Using System. net;
Using System. Threading;
NamespaceSend
{
ClassProgram
{
Static VoidMain (String[] ARGs)
{
Socket s= NewSocket (addressfamily. InterNetwork, sockettype. dgram, protocoltype. UDP );
byte [] buffer = encoding. unicode. getbytes ( " Hello World " );
ipendpoint IEP = New ipendpoint (IPaddress. parse ( " 234.5.6.7 " ), 4567 );
IntI= 0;
While(True)
{
Console. writeline ("In progress {0}", I++. Tostring ());
S. sendto (buffer, IEP );
Thread. Sleep (5000);
}
}
}
}
By default, the TTL of the IP multicast data packets sent is equal to 1, so that they cannot be sent from the subnet.
3. Results