udp组播 java,Windows 8.1 UDP组播

I'm having a problem getting UDP multicast send to work from Windows 8.1.

The following simple test program works from within an interface-bridged VM running Windows 7 or Ubuntu 13 on the same host. For this reason I am sure that the issue is not with the java test program, or with the physical network configuration.

import java.net.*;

public class multicast_send {

public static void main(String[] args) throws Exception {

DatagramSocket socket = null;

DatagramPacket outPacket = null;

socket = new DatagramSocket();

String msg = "Multicast Test";

outPacket = new DatagramPacket(msg.getBytes(), msg.getBytes().length, InetAddress.getByName("230.0.0.1"), 4446);

socket.send(outPacket);

System.out.println("Server sent : " + msg);

socket.close();

}

}

The failure under windows 8.1 manifests itself as a silent failure, i.e. the message just does not arrive at a remote host.

I've used WireShark on the Windows 8.1 host and I see no evidence of the UDP packets being sent.

The Windows 8.1 firewall is disabled.

I have tried a range of multicast addresses and ports with the same result (works from Win7, Ubuntu, not Windows 8.1)

From browsing the inter-web I notice there are a few descriptions of UDP Multicast issues introduced in Windows 8.1; but this case does not seem to match the issue descriptions.

The java environment is 1.7.0.51b13 in all three cases.

Is there some hidden widget I need to tweak in Windows 8.1 to enable Multicast UDP? Is there a glaringly obvious code problem I'm not spotting which is Windows 8.1 specific?

解决方案

The solution is that windows 8.1 has access to more than one interface, the Ethernet adapter and multiple VM bridging adapters.

Similar to the resolution to other win8.1 UNDP issues, it appears that unlike other OS, there is no default interface selected for the UDP send, so successful multicast relies on assigning explicitly an interface to the socket.

Socket.setinetrface.getbyname("ip address of Ethernet adapter")

As soon as I do that, it works as expected.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值