I have a web service and on startup I wanted to announce the service with a UPnP compatible NOTIFY to the local network. If possible I won't include a lib (like cling) and make it simple as possible.
The code so far:
String NOTIFY
= "NOTIFY * HTTP/1.1\r\n"
+ "NTS:ssdp:alive\r\n"
+ "Location: http://192.168.1.10\r\n\r\n";
InetAddress addr;
MulticastSocket socket;
DatagramPacket dp;
try {
addr = InetAddress.getByName("239.255.255.250");
socket = new MulticastSocket(1900);
socket.setReuseAddress(true);
socket.setSoTimeout(3000);
socket.joinGroup(addr);
byte[] buf = NOTIFY.getBytes("UTF-8");
dp = new DatagramPacket(buf, buf.length, addr, 1900);
// send out 10 notifys, then stop to send
for (int i = 10; i > 0; i--) {
socket.send(dp);
Thread.sleep(3000);
}
} catch (Exception ex) {
System.err.println(ex);
}
I'm checking back with the Clink workbench, but I get nothing listed in the UI. Propably the message is not appropiated formated ?