Win8: DatagramSocket.send to multicast addr silently failes

85 views Asked by At

I am trying to write a very simple SSDP discovery routine for a certain UPnP-enabled TV. Here is a stripped-down version of my code:

private void discover() {

String header = "M-SEARCH * HTTP/1.1";
String[][] fields = new String[][] {
        {"ST", "ssdp:all"},
        {"MAN", "\"ssdp:discover\""},
        {"HOST", "239.255.255.250:1900"},
        {"MX", "10"}};

String p=this.make_packet(header, fields);

MulticastSocket s = null;
ArrayList<String> devices=new ArrayList<String>();
String[] ret;
String[] loc;

try {
    InetAddress addr=InetAddress.getByName("239.255.255.250");
    s = new MulticastSocket(1900);
    s.setReuseAddress(true);
    s.setSoTimeout(3000);
    s.joinGroup(addr);

    DatagramPacket pack=new DatagramPacket(p.getBytes("UTF-8"), p.length(), addr, 1900);
    s.send(pack);

    byte[] buffer=new byte[1024];

    DatagramPacket packrec=new DatagramPacket(buffer, 1024);

    for(;;) {
        System.out.println("Waiting for response...");
        s.receive(packrec);
        System.out.println(new String(buffer, 0, packrec.getLength()));
    }

} catch (Exception e) {
    System.out.println(e);
}

}

I compile and run the code on a Win8 machine via console. The socket always received exactly one response: a 1:1 copy of the message to be sent. This is probably correct, I guess, since the socket joins the multicast group in the beginning. However, no other UPnP devices reply, although I can see them in 3rd party UPnP inspectors.

When watching the network traffic with WireShark, no package seems to get sent by my code at all, although no exception is thrown. When scanning the network with a different UPnP inspector from the same machine, outbound packages are logged in WireShark (although oddly the replies of some devices are not, even though the inspector finds them).

I am messing around with this for four days now, but to no avail. Any ideas?

Thanks, Eric

P.S.: JDK 1.8.0_45 (64bit)

0

There are 0 answers