Multicast receiver unable to capture the data

断了今生、忘了曾经 提交于 2019-12-12 22:33:48

问题


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?

来源:https://stackoverflow.com/questions/45162552/multicast-receiver-unable-to-capture-the-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!