`

upnp初始化

    博客分类:
  • upnp
 
阅读更多
/*
 * Copyright (C) 2010 Teleal GmbH, Switzerland
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.teleal.cling;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionArgumentValue;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.message.header.STAllHeader;
import org.teleal.cling.model.meta.Action;
import org.teleal.cling.model.meta.LocalDevice;
import org.teleal.cling.model.meta.RemoteDevice;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.model.types.UDAServiceId;
import org.teleal.cling.registry.Registry;
import org.teleal.cling.registry.RegistryListener;

/**
 * Runs a simple UPnP discovery procedure.
 * <p>
 * Call this class from the command-line to quickly evaluate Cling, it will
 * search for all UPnP devices on your LAN and print out any discovered, added,
 * and removed devices while it is running.
 * </p>
 *
 * @author Christian Bauer
 */
public class MyMain {

    public static void main(String[] args) throws Exception {
        System.out.println("Starting Cling...");
        
        UpnpService upnpService = new UpnpServiceImpl(
                new RegistryListener() {
                    public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice device) {
                        System.out.println("Discovery started: " + device.getDisplayString());
                    }
                    public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice device, Exception ex) {
                        System.out.println("Discovery failed: " + device.getDisplayString() + " => " + ex);
                    }
                    public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
                        System.out.println("Remote device added: " + device.getDisplayString());
                    }
                    public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
                        System.out.println("Remote device updated: " + device.getDisplayString());
                    }
                    public void remoteDeviceRemoved(Registry registry, RemoteDevice device) {
                        System.out.println("Remote device removed: " + device.getDisplayString());
                    }
                    public void localDeviceAdded(Registry registry, LocalDevice device) {
                        System.out.println("Local device added: " + device.getDisplayString());
                    }
                    public void localDeviceRemoved(Registry registry, LocalDevice device) {
                        System.out.println("Local device removed: " + device.getDisplayString());
                    }
                    public void beforeShutdown(Registry registry) {
                        System.out.println("Before shutdown, the registry has devices: " + registry.getDevices().size());
                    }
                    public void afterShutdown() {
                        System.out.println("Shutdown of registry complete!");
                    }
                }
        );
        upnpService.getControlPoint().search(new STAllHeader()); // Search for all devices and services
       Thread.sleep(10000); //暂停5秒 查找设备
        
        
        Collection<RemoteDevice> dss = upnpService.getRegistry().getRemoteDevices();
        MyMain mian = new MyMain();
        for(RemoteDevice device:dss){
        	Map<String,Object> inputs = new HashMap<String,Object>();
        	inputs.put("ObjectID","200/516/517");
        	inputs.put("BrowseFlag","BrowseDirectChildren");
        	inputs.put("Filter","*");
            inputs.put("StartingIndex","0");
            inputs.put("RequestedCount","0");
            inputs.put("SortCriteria","");
        	Map outputs = new HashMap();
        	outputs = mian.action(upnpService, device, "ContentDirectory", "Browse", inputs);
        	Set<String> keys = outputs.keySet();
        	for(String key:keys){
        		System.out.println("key:"+key+"  values:"+outputs.get(key));
        	}
        	/*Service service = device.findService(new UDAServiceId("ContentDirectory"));
            Action getStatusAction = service.getAction("Browse");
            ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);*/
           /* //取第一个目录数据
            getStatusInvocation.setInput("ObjectID", "200/516");
            getStatusInvocation.setInput("BrowseFlag", "BrowseDirectChildren");
            getStatusInvocation.setInput("Filter", "*");
            getStatusInvocation.setInput("StartingIndex", "0");
            getStatusInvocation.setInput("RequestedCount", "0");
            getStatusInvocation.setInput("SortCriteria", "+dc:creator"); //按照 创建时间排序
*/         /* //取根目录数据
            getStatusInvocation.setInput("ObjectID", "0");
            getStatusInvocation.setInput("BrowseFlag", "BrowseDirectChildren");
            getStatusInvocation.setInput("Filter", "*");
            getStatusInvocation.setInput("StartingIndex", "0");
            getStatusInvocation.setInput("RequestedCount", "3");
            getStatusInvocation.setInput("SortCriteria", "");*/
            //根目录元数据
            /*getStatusInvocation.setInput("ObjectID", "0");
            //getStatusInvocation.setInput("BrowseFlag", "BrowseDirectChildren");
            getStatusInvocation.setInput("BrowseFlag", "BrowseMetadata");
            getStatusInvocation.setInput("Filter", "*");
            getStatusInvocation.setInput("StartingIndex", "0");
            getStatusInvocation.setInput("RequestedCount", "0");
            getStatusInvocation.setInput("SortCriteria", "");*/
            
            //同步action 但是也没有发现怎么同步了 ,之前需要sleep
        	/*new ActionCallback.Default(getStatusInvocation, upnpService.getControlPoint()).run();
        	Map map = getStatusInvocation.getOutputMap();
        	ActionArgumentValue ss = getStatusInvocation.getOutput("Result");
        	System.out.println(ss.getValue());*/
        	
        	
        	//异步action
        	/* Service service = device.findService(new UDAServiceId("ContentDirectory"));
             Action getStatusAction = service.getAction("GetSearchCapabilities");
             ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);
             //getStatusInvocation.setInput("SourceURI", "");
             //getStatusInvocation.setInput("DestinationURI", "");
             ActionCallback getStatusCallback = new ActionCallback(getStatusInvocation) {

                  public void success(ActionInvocation invocation) {
                      ActionArgumentValue status  = invocation.getOutput("SearchCaps");
                     System.out.println(status.getValue());
                      //assertEquals((Boolean) status.getValue(), Boolean.valueOf(false));
                  }
                  @Override
                  public void failure(ActionInvocation invocation, UpnpResponse res) {
                      System.err.println(
                          createDefaultFailureMessage(invocation, res)
                      );
                  }
					@Override
					public void failure(ActionInvocation invocation,
							UpnpResponse operation, String defaultMsg) {
						System.err.println(
                              createDefaultFailureMessage(invocation, operation)
                          );
					}
             };
             upnpService.getControlPoint().execute(getStatusCallback);*/
        }
        System.out.println("Stopping Cling...");
        upnpService.shutdown();
    }
    public Map action(UpnpService upnpService, RemoteDevice device, String serviceId, String actionId, Map inputs){
    	Map retMap = null;
    	Service service = device.findService(new UDAServiceId(serviceId));
        Action getStatusAction = service.getAction(actionId);
        ActionInvocation getStatusInvocation = new ActionInvocation(getStatusAction);
        Set<String> keys = inputs.keySet();
        for(String key:keys){
        	getStatusInvocation.setInput(key, inputs.get(key));
        }
        new ActionCallback.Default(getStatusInvocation, upnpService.getControlPoint()).run();
        retMap = getStatusInvocation.getOutputMap();
        System.out.println(retMap.size());
        return retMap;
    }
}

 

附件为文件管理开发文档

分享到:
评论

相关推荐

    Upnp TEST 测试器

    That is where the UPnP Test application comes in. This simple program is designed to help you identify the issues that prevent the UPnP protocol from functioning correctly. Before you get your hopes...

    路由后台进行查看UPNP功能是否开启

    1、操作系统是否支持UPnP功能:Windows XP,Vista,Windows 7均支持UPnP功能,Windows 2003不支持UPnP功能 2、SSDP服务是否已经启动:SSDP在Windows服务里名字是“SSDP Discovery Service”,如此项FAILED,请使用...

    upnp-bhunter:Burp Suite Extension对检查UPnP安全性很有用

    UPnP BHunter描述UPnP BHunter是用Python / Jython编写的Burp Suite扩展,可用作UPnP渗透测试工具,用于查找活动的UPnP服务/设备并提取相关的SOAP,Subscribe和Presentation请求(支持IPv4和IPv6),然后对其进行...

    Win7 开启upnp服务

    Win7 开启upnp服务

    UPNP开发 参考文档

    UPNP开发的相关文档、介绍upnp以及upnp协议的使用

    基于UPnP的穿越NAT的技术

    基于UPnP可以双向穿越Full...基于UPnP的方法不能穿越多级NAT,因为UPnP Internet Gateway Device V1.0(IGD)目前不支持多级NAT 基于UPnP的方法需要NAT设备和内网主机的应用程序支持UPnP,不需要另外添加服务器或代理。

    upnp 小型客户端源码

    可跨平台 (pc linux ios 等等 upnpDiscover() UPNP GetValidIGD() UPNP AddPortMapping() UPNP DeletePortMapping

    upnp库(c++代码)

    dlna协议中的upnp部分,c++代码,android开发的引用库函数。

    UPnP协议编程实践

    本文是《UPnP编程实践》系列的第二篇,主要介绍UPnP的设备发现过程的协议实现。关于UPnP协议的框架性介绍,您可以参考《UPnP编程实践》系列的第一篇。UPnP协议的设备发现过程使用简单服务发现协议,此协议实现了在...

    delphi upnp 组件包

    delphi upnp 组件包 ,便于在delphi 环境下开发upnp项目。

    UPnP™设备架构1.0-Chinese_

    UPnP是针对智能家电、无线设备以及各种外观尺寸的个人电脑的普遍对等(peer-to-peer)网络连接而设计的一种架构。它旨在为家庭、小型企业、公共场所中或连接到互联网的ad-hoc网或未管理网络提供易于使用、灵活且基于...

    c# upnp TCP 穿透

    c# upnp , 国内UPNP 在C# 方面的资料几乎看不见。从code project 上淘下来的,不容易。 需要进行UPNP 点对点TCP 穿透的朋友,可以参考下

    UPNP端口映射

    UPnP 是各种各样的智能设备、无线设备和个人电脑等实现遍布全球的对等网络连接(P2P)的结构。 UPNP端口映射主要作用: 1、对于一台内网电脑,UPnP功能可以使网关或路由器的NAT模块做自动端口映射,将你程序所监听的...

    upnp成功1.1.pcapng

    upnp开启,使用比特彗星软件能看到upnp nat成功映射

    UPNP IGD家庭网关标准

    基于UPNP的网关设计标准,组件,为UPNP标准设备描述文档

    UPnP Android代码实现

    UPnP协议,用Android 码实现的Demo

    经典的查找UPnP软件

    一个UPnP操作软件,非常的不错,点击查找立即自动寻找当前是否开启upnp

    upnpserver, 用于 node的快速和轻型upnp服务器.zip

    upnpserver, 用于 node的快速和轻型upnp服务器 upnpserver UpnpServer是一个用NodeJS编写的快速而轻型的UPnP服务器。 这里版本不需要外部数据库( 。mysql,mongodb ),它将所有信息存储在内存中。兼容性Freebox高清S

Global site tag (gtag.js) - Google Analytics