我在java应用程序中看不到udp多播通信,但我可以从wireshark中看到

kxxlusnw  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(302)

我正在尝试加入udp多播组,以便在jdk1.8+环境下的windows7中接收udp数据。
我正在使用nio datagramchannel接收数据。似乎我的程序工作得很好,因为我可以看到udp流量来通过wireshark一旦我加入了多播组程序未运行时,我看不到任何udp通信。)

InetAddress group = InetAddress.getByName(UDPGROUP_IP);
NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getByName(MY_IP));
DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET) ;

channel.setOption(StandardSocketOptions.SO_REUSEADDR, true).bind(new InetSocketAddress(port));
channel.join(group,ni);

channel.configureBlocking(false);

SocketAddress sa;
ByteBuffer buf = ByteBuffer.allocate(1024);

sa = channel.receive(buf);
if (sa != null ){

    byte[] byteReceived = new byte[BYTELEN]; 
    buf.flip();
    buf.get(byteReceived, 0, buf.limit());

    DefaultLogger.logger.info("Received :{}" , new String(byteReceived));

}

但是当我尝试接收上面这样的数据时,它总是返回null。我以前用不同的env运行这个程序,到目前为止效果很好。我找不到任何线索来解决这个问题。
我将感谢任何帮助或暗示。

r7xajy2e

r7xajy2e1#

我真傻,连防火墙都没想过。安装在这台电脑上的第三方安全软件保护我的程序接收数据包。
谢谢,伙计们。

相关问题