0
我有一個Web服務,並在啓動時我想宣佈服務與UPnP兼容NOTIFY到本地網絡。如果可能的話,我將不包含一個lib(如緊抱)並儘可能簡化。宣佈我的服務與「UPnP」
至今代碼:
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);
}
我檢查回來碰杯工作臺,但是我什麼也得不到的UI上市。顯然這個信息不適用于格式化?