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) algorithm version 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 = new IPEndPoint (IPAddress. Any, 4567 );
EndPoint ep = (EndPoint) ipe;
S. Bind (ep );
// 3 add to multicast group 234.5.6.7
MulticastOption optionValue = new MulticastOption (IPAddress. Parse ("234.5.6.7 "));
S. SetSocketOption (SocketOptionLevel. IP, SocketOptionName. AddMembership, optionValue );
// 4 receive multicast group data
Console. WriteLine ("start receiving data on 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