Linux configuration and test IP multicast (multicast)

Source: Internet
Author: User


224.0.0.0 to 239.255.255.255 these are called multicast addresses.


Let me give you a less rigorous example.
There are several hosts that have joined the 224.1.1.1 group.
192.168.1.1---192.168.1.2---192.168.1.3---such as these three IP addresses joined the group 224.1.1.1
Then the multicast source 10.1.1.1---Send information to 224.1.1.1 this group address, the group of the host will receive the multicast source sent information ... If you use ICMP to detect the multicast source 10.1.1.1 ping 224.1.1.1 can be used to prove that the multicast is the next group of members received the multicast information


So let's do multicast configuration work


First of all:

Ifconfig-a


When we examine eth0 and do not see multicast, we need to enter an instruction to make it appear:

Ifconfig eth0 Multlicast


So here's the problem. There is no eth0 in the new version, but eno16777736,so: we need to change eno16777736 to Eth0

Workaround: http://jingyan.baidu.com/article/6181c3e081f178152ef1538f.html

Well, multicast is now enabled. Now you need to add IP routing for the D-Class multicast network. Then you need to add the following path:

#route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0


So what's a D-level multicast address?

Class D addresses are used for multipoint broadcasts (multicast).

Class D IP Address the first byte begins with "1110", which is a specially reserved address. It does not point to a particular network, which is currently used in multipoint broadcasts (multicasting). Multicast addresses are used to address a group of computers at a time, identifying a group of computers that share the same protocol.

The IP address of Class D does not identify the network, and its address coverage is 224.0.0.0~239.255.255.255.

Next we can test the IP multicast Java program with two machines on a single machine or LAN, as follows:

import java.net.datagrampacket; import java.net.inetaddress; import  java.net.multicastsocket; import javax.swing.text.utilities; public class  multicastnode { inetaddress group = null; multicastsocket s =  Null; public static void main (String[] args)  { if  (args.length  > 0)  { system.out.println ("Sending message:"  + args[0]);  MulticastNode  node = new multicastnode ();  node.send (Args[0]);  node.receive (); }  Else { system.out.println ("Need an argument string to send.");  system.exit (1);  } } public multicastnode ()  { try { group =  inetaddress.getbyname ("224.0.0.1");  s = new multicastsocket (45564);  s.joinGroup (group); } catch  (exception e)  {  E.printstacktrace ();  } } public void send (string msg)  { try {  datagrampacket hi = new datagrampacket (Msg.getbytes (),  msg.length (),  group ,  45564);  s.send (HI); } catch  (exception e)  { e.printstacktrace ();  } } public void receive ()  { byte[] buf; while  (true)  {  try { buf = new byte[1000]; DatagramPacket recv = new  Datagrampacket (buf, buf.length);  s.receive (recv);  system.out.println ("Received:"  +  New string (BUF)); } catch  (exception e)  { e.printstacktrace (); }  } } }



This Java program primarily needs to be aware of group = Inetaddress.getbyname ("224.0.0.1"); This is the address that refers to your multicast address, not your IP address, I am joining a unified multicast address via a host of different IP addresses 224.0.0.1 (if your program does not report a multicast address, you will need to see how the multicast addresses are queried)

The multicast Address Query method is:

Netstat-gn


Put this Java program into a jar package in Linux or window, by typing

1.
Java-jar Mult.jar Nodeone

(Please change the name of your jar bag)
2.

Java-jar Mult.jar Nodetwo



The effect should be sending Message:nodeone
Received:nodeone
Received:nodetwo
I tested it with window, and the results were the same on Linux, as follows:



650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0119/2467/ 3d7597ab-36ca-376d-b48f-c4975848691f.png "alt=" 3d7597ab-36ca-376d-b48f-c4975848691f.png "/>


650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0119/2471/ D512612d-2bf7-3a3f-8507-79383c0b9efb.png "style=" white-space:normal; "alt=" D512612d-2bf7-3a3f-8507-79383c0b9efb.png "/>


650) this.width=650; "Src=" http://dl2.iteye.com/upload/attachment/0119/2469/ 2ecbc181-974d-3f65-b9bf-ad914956a63f.png "alt=" 2ecbc181-974d-3f65-b9bf-ad914956a63f.png "/>



This article is from the "Heritage" blog, please be sure to keep this source http://10146719.blog.51cto.com/10136719/1836886

Linux configuration and test IP multicast (multicast)

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.