问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/21351427/windows-8-1-udp-multicast