我有一个可以在 UPnP 搜索中找到的相机。它还每 150 秒通告(多播)与 UPnP 搜索相同的响应。
我创建了一个 android 应用程序,它可以通过 UPnP 搜索或仅收听多播广告来识别相机。
我通过创建一个多播套接字并监听任何数据包来实现广告监听
new Thread(new Runnable() {
public void run() {
try{
Utils.showLog(TAG,"Searching Thread Started " );
// Get the address that we are going to connect to.
InetAddress address = InetAddress.getByName(INET_ADDR);
// Create a buffer of bytes, which will be used to store
// the incoming bytes containing the information from the server.
// Since the message is small here, 256 bytes should be enough.
byte[] buf = new byte[512];
// Create a new Multicast socket (that will allow other sockets/programs
// to join it as well.
try {
clientSocket = new MulticastSocket(PORT);
//Joint the Multicast group.
clientSocket.joinGroup(address);
isSocketOpen=true;
while (isSocketOpen) {
// Receive the information and print it.
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length);
clientSocket.receive(msgPacket);
Utils.showLog(TAG, "------>SocketAddress: " + msgPacket.getSocketAddress());
Utils.showLog(TAG,"------>Port " + msgPacket.getPort());
String URL =getLocation(msgPacket).trim();
}
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
}
}).start();
现在我的问题是,在华硕 Zenfone(Android 5.0 版)上,它工作正常,但在联想 A1000(相同的安卓版本)上却失败了。
Lenovo A1000 可以从 Windows PC 捕获 SSDP 数据包。问题仅与来自我的相机的数据包有关。
但是如果来自摄像头的数据包被破坏,那么它是如何在华硕 Zenfone 中捕获的呢?
我的问题是android会在到达我的应用程序之前阻止任何数据包吗?