UPnP数据包未收到

时间:2016-04-19 12:31:14

标签: android upnp packets ssdp

我有一台可以在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();

现在我的问题是在Asus Zenfone(Android 5.0版)上,它的工作正常,但在联想A1000(同样的andoid版本)上却失败了。

联想A1000可以从Windows PC上捕获SSDP数据包。但是我的相机只能使用数据包。

但如果来自相机的数据包被破坏,那么它是如何在华硕Zenfone中捕获的?

我的问题是android会在到达我的应用程序之前阻止任何数据包吗?

0 个答案:

没有答案