Multicast receiver unable to capture the data

2019-07-28 03:12发布

问题:

I want to capture network traffic on specific Multicast IP address and port number.

For testing purpose, I replay pcap file over a network on 225.1.1.7 ip and 3100 port.

I tried to capture using tcpdump using below command -

sudo tcpdump -i eno1 -s0 -vv host 225.1.1.7 and port 3100

and it is working file.

I have below java program -

class Temp {

    public static void main(String[] args) throws UnknownHostException, IOException {

        int port = 3100;
        String group = "225.1.1.7";

        MulticastSocket s = new MulticastSocket(port);

        s.joinGroup(InetAddress.getByName(group));

        byte buf[] = new byte[1024];
        DatagramPacket pack = new DatagramPacket(buf, buf.length);
        s.receive(pack);

        System.out.println("Received data from: " + pack.getAddress().toString()
                + ":" + pack.getPort() + " with length: "
                + pack.getLength());
        System.out.write(pack.getData(), 0, pack.getLength());

        s.leaveGroup(InetAddress.getByName(group));
        s.close();

    }
}

why above java program will not receive any data from same multicast ip and port?