我試圖在Android中使用java實現DIAL protocol。從M-SEARCH Response獲取位置標題
遵循協議實現,我必須做一個M-SEARCH請求。爲此,我使用以下代碼:
private final static String DISCOVER_MESSAGE = "M-SEARCH * HTTP/1.1\r\n"
+ "HOST: 239.255.255.250:1900\r\n" + "MAN: \"ssdp:discover\"\r\n"
+ "MX: 120\r\n" + "ST: urn:dialmultiscreenorg:service:dial:1\r\n";
和實際的方法:
// Set the MulticastSocket to DIAL implementation.
// See the Discover Message for its full implementation.
final int port = 1900;
InetAddress multicastAddress = InetAddress.getByName("239.255.255.250");
MulticastSocket usedSocket = new MulticastSocket(port);
usedSocket.setReuseAddress(true);
usedSocket.setSoTimeout(130000);
usedSocket.joinGroup(multicastAddress);
byte[] requestMessage = DISCOVER_MESSAGE.getBytes("UTF-8");
DatagramPacket datagramPacket = new DatagramPacket(requestMessage,
requestMessage.length, multicastAddress, port);
// Send the package.
usedSocket.send(datagramPacket);
// Listen for the response.
byte[] buf = new byte[9000];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
usedSocket.receive(packet);
response = new String(packet.getData());
我現在遇到的問題是,根據本說明書中:
的SSDP /接收具有上述搜索目標的M-SEARCH請求的UPnP服務器應按照1的第1.3.3節中的定義進行響應,包括包含用於根設備的UPnP描述的絕對HTTP URL的LOCATIONheader。 URL的主機部分應解析爲IPv4地址或IPv4地址。
但所有我在迴應包獲得,似乎是我送了相同的數據。
這可能是由於我錯誤的閱讀回覆,我不確定。如何從這個M-SEARCH響應中獲取位置標題?
這可能是由錯誤的M-SEARCH請求引起的嗎?