Jump to content
C4 Forums | Control4

c4Discovery


esmadja

Recommended Posts

In 2013 a file called c4Discovery.java was posted I am trying to use it and I get a time out.  I thought that at one point I had got this to work using port 1902 and that doesn't work either.

Any help as to what I am doing wrong would be appreciated.

Thanks,

This is the code

import java.io.*;
import java.net.*;
public class c4Discovery{
          public static void main(String args[]) throws Exception{
              DatagramSocket c4Socket = new DatagramSocket();
              InetAddress group = InetAddress.getByName("239.255.255.250");
              byte[] sendData = new byte[0];
              byte[] receiveData = new byte[128];
             
              String message =  "M-SEARCH * HTTP/1.1\r\n"
                              + "HOST: 239.255.255.250:1900\r\n"
                              + "MAN: \"ssdp:discover\"\r\n"
                              + "MX: 5\r\n"
                              + "ST: c4:director\r\n"
                              + "\r\n";
    
              sendData = message.getBytes();
              DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, group, 1900);
             
              try{
                   c4Socket.send(sendPacket);
                   c4Socket.setSoTimeout ( 3000 );
                   System.out.println("sent packet...");
                   DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
                   c4Socket.receive(receivePacket);
                   InetAddress controllerAddress = receivePacket.getAddress();
                   String controllerResponse = new String(receivePacket.getData());
                   System.out.println("response!\n" +controllerResponse + "\n" +controllerAddress);
                   c4Socket.close();
              } 
              catch (IOException e) 
              { 
              System.err.println ("I/O - " + e); 
              } 
        }
}
Link to comment
Share on other sites


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.