Atitit.upnp SSDP 查找nas的原理与实现java php c#.net c++

1. 查找nas的原理1

2. 与dlna的关系1

3. 与ssdp的关系1

4. Cling - Java/Android UPnP library and tools3

5. 框架 java。Net3

6. Cling  Code----4

6.1. 主要流程说明。。建立UpnpService  发出查询请求4

6.2. // Let's wait 10 seconds for them to respond4

6.3. 通过回调监听器得到nas的ip地址4

6.4. Code--5

7. 参考8

1. 查找nas的原理

准备使用smb协议,但是使用unc好像太慢,直接使用smb 其ip都返回true;

或许使用ip/path的方式是可以的。。

而且也没办法区分nas和pc

只好使用upnp ssdp协议来发现nas了。。

2.  与dlna的关系

dlna是一套标准,是由微软,因特尔,索尼等大厂商组成的联盟,他们制定了一套标准让大家去用。其实dlna基本没做什么事,里面用到的协议都是现成的,而upnp是dlna进行设备控制的一个最基本的协议。如果要有dlna做了什么的话,那么就是把upnp这套协议的内容用在了数字家庭领域。使它得到了极大的发展

作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://blog.csdn.net/attilax

3. 与ssdp的关系

简单服务发现协议(SSDP,Simple Service Discovery Protocol)是一种应用层协议,是构成通用即插即用(UPnP)技术的核心协议之一。

SSDP:Simple Sever Discovery Protocol,简单服务发现协议,此协议为网络客户提供一种无需任何配置、管理和维护网络设备服务的机制。此协议采用基于通知和发现路由的多播发现方式实现。协议客户端在保留的多播地址:239.255.255.250:1900(IPV4)发现服务,

SSDP 协议消息

1、设备查询消息

当一个控制点加入到网络中时,设备发现过程允许控制点寻找网络上感兴趣的设备。发现消息包括设备的一些特定信息或者某项服务的信息,例如它的类型、标识符、和指向XML设备描述文档的指针。从设备获得响应从本质上说,内容与多址传送的设备广播相同,只是采用单址传送方式。设备查询通过HTTP协议扩展M-SEARCH方法实现的。典型的设备查询请求消息格式:

M-SEARCH * HTTP/1.1

HOST: 239.255.255.250:1900

MAN: "ssdp:discover"

MX: seconds to delay response

ST: search target

在设备接收到查询请求并且查询类型(ST字段值)与此设备匹配时,设备必须向多播地址239.255.255.250:1900回应响应消息。典型:

HTTP/1.1 200 OK

CACHE-CONTROL: max-age = seconds until advertisement expires

DATE: when reponse was generated

EXT:

LOCATION: URL for UPnP description for root device

SERVER: OS/Version UPNP/1.0 product/version

ST: search target

USN: advertisement UUID

4. Cling - Java/Android UPnP library and tools

3.2. Client operations with ControlPoint

Your primary API when writing a UPnP client application is the ControlPoint. An instance is available with getControlPoint() on the UpnpService.

public interface ControlPoint {



    public void search(UpnpHeader searchType);

    public void execute(ActionCallback callback);

    public void execute(SubscriptionCallback callback);



}

5. 框架 java。Net

import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetSocketAddress;

import java.net.MulticastSocket;

import java.net.NetworkInterface;

import java.net.SocketAddress;

import java.util.Scanner;

import android.content.Context;

import android.util.Log;

6. Cling  Code----

6.1. 主要流程说明。。建立UpnpService  发出查询请求

final UpnpService upnpService = new UpnpServiceImpl(listener);

upnpService.getControlPoint().search(

new STAllHeader()

);

6.2. // Let's wait 10 seconds for them to respond

System.out.println("Waiting 10 seconds before shutting down...");

Thread.sleep(10000);

6.3. 通过回调监听器得到nas的ip地址

"presentationURI": "http://192.168.2.105:5000/",

6.4. Code--

public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

//UpnpServiceImpl us=new UpnpServiceImpl();

//  for  (Device device : us.getRegistry().getDevices()) {

//           System.out.println(AtiJson.toJson(device));

//        }

// UPnP discovery is asynchronous, we need a callback

RegistryListener listener = 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 available: " + device.getDisplayString()

);

System.out.println(  AtiJson.toJson(device)  );

}

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!");

}

};

// This will create necessary network resources for UPnP right away

System.out.println("Starting Cling...");

//   UpnpService upnpService = new UpnpServiceImpl(listener);

final UpnpService upnpService = new UpnpServiceImpl(listener);

upnpService.getControlPoint().search(

new STAllHeader()

);

// Let's wait 10 seconds for them to respond

System.out.println("Waiting 10 seconds before shutting down...");

Thread.sleep(10000);

//----------------------

//  Registry registry = upnpService.getRegistry();

//Collection<Device> foundDevice = registry.getDevices();

//  for (Device device : foundDevice) {

//System.out.println(AtiJson.toJson(device));

//}

//

// Release all resources and advertise BYEBYE to other UPnP devices

System.out.println("Stopping Cling...");

//     upnpService.shutdown();

System.out.println("--f");

Ret device

Remote device available: Synology DS213+ DS213+ 5.2-5644

{

"identity": {

"descriptorURL": "http://192.168.2.105:5000/ssdp/desc-DSM-eth0.xml",

"discoveredOnLocalAddress": "192.168.2.99",

"udn": {

"identifierString": "73796E6F-6473-6D00-0000-0011321cb389"

},

"maxAgeSeconds": 1900

},

"version": {

"major": 1,

"minor": 0

},

"type": {

"namespace": "schemas-upnp-org",

"type": "Basic",

"version": 1

},

"details": {

"friendlyName": "dy (DS213+)",

"manufacturerDetails": {

"manufacturer": "Synology",

"manufacturerURI": "http://www.synology.com"

},

"modelDetails": {

"modelName": "DS213+",

"modelDescription": "Synology NAS",

"modelNumber": "DS213+ 5.2-5644",

"modelURI": "http://www.synology.com"

},

"serialNumber": "0011321cb389",

"presentationURI": "http://192.168.2.105:5000/",

"dlnaDocs": []

},

"icons": []

}

7. 参考

java - SSDP & Android, how to reply to a M-SEARCH - Stack Overflow.htm

SSDP协议 - java学习之简单开发快乐学习 - ITeye技术网站.htm

Cling核心手册 - zangcf的专栏 - 博客频道 - CSDN.NET.htm

jcifs lib can't detect NAS - Meggie_love的专栏 - 博客频道 - CSDN.NET.htm

Atitit.upnp SSDP 查找nas的原理与实现java php c#.net c++的更多相关文章

  1. Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构

    Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构 1. 索引的分类1 1.1. 按照存储结构划分btree,hash,bitmap,fulltext1 1.2. 索引的类型  按查找 ...

  2. Atitit web remote远程调试的原理attilax总结

    Atitit web remote远程调试的原理attilax总结 Jvm是vm打开一个debug port,然后ide先连接..然后执行url,就会vm会与ide沟通.. Php的xdebug po ...

  3. Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构

    Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构 1. 索引的分类1 1.1. 索引的类型  按查找方式分,两种,分块索引 vs编号索引1 1.2. 按索引与数据的查找顺序可分为 正 ...

  4. Atitit Data Matrix dm码的原理与特点

    Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...

  5. Atitit 深入理解耦合Coupling的原理与attilax总结

    Atitit 深入理解耦合Coupling的原理与attilax总结     耦合是指两个或两个以上的电路元件或电网络等的输入与输出之间存在紧密配合与相互影响,并通过相互作用从一侧向另一侧传输能量的现 ...

  6. Atitit 异常机制与异常处理的原理与概论

    Atitit 异常机制与异常处理的原理与概论 1. 异常vs 返回码1 1.1. 返回码模式的处理 (瀑布if 跳到失败1 1.2. 终止模式  vs 恢复模式(asp2 1.3. 异常机制的设计原理 ...

  7. Atitit.gui api自动化调用技术原理与实践

    Atitit.gui api自动化调用技术原理与实践 gui接口实现分类(h5,win gui, paint opengl,,swing,,.net winform,)1 Solu cate1 Sol ...

  8. Atitit 网络爬虫与数据采集器的原理与实践attilax著 v2

    Atitit 网络爬虫与数据采集器的原理与实践attilax著 v2 1. 数据采集1 1.1. http lib1 1.2. HTML Parsers,1 1.3. 第8章 web爬取199 1 2 ...

  9. Atitit.实现继承的原理and方法java javascript .net c# php ...

    Atitit.实现继承的原理and方法java javascript .net c# php ... 1. 实现继承的问题 1 2. 如何拷贝基类方法?采用prototype原型方式,通过冒充对象 1 ...

随机推荐

  1. CentOS7安装bind域名服务

    安装Bind Chroot DNS 服务器 yum install bind-chroot bind -y 拷贝bind相关文件,准备bind chroot 环境 cp -R /usr/share/d ...

  2. (转) C#解惑:HashSet<T>类

    HashSet<T>是一个相对“冷门”的类型,平时在项目中用得不多,但是在特定的业务中可以大用. 先来了解下HashSet<T>类,主要被设计用来存储集合,做高性能集运算,例如 ...

  3. Oracle 后台进程

    一.基本后台进程       1.数据库写入进程(DBWn):       数据库写入程序讲数据库告诉缓存区中的修改块写入数据文件.对于多数系统来说,一个数据库写入程序(DBW0)就已经足够,但是对于 ...

  4. POJ 2763 Housewife Wind(树链剖分+树状数组)

    [题目链接] http://poj.org/problem?id=2763 [题目大意] 在一棵树上,给出一些边的边长,有修改边的边长的操作, 询问每次从当前点到目标点的最短距离 [题解] 树链剖分之 ...

  5. 【分块】hdu5057 Argestes and Sequence

    分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...

  6. [CF842E]Nikita and game

    [CF842E]Nikita and game 题目链接: CF842E 博客地址: [CF842E]Nikita and game - skylee 题目大意: 一棵树初始只有一个编号为\(1\)的 ...

  7. Android 架构 2.界面

    其中,最上层的界面,是变化最频繁的一个层面,也是最复杂最容易出问题的一个层面,如果规划不好,很容易做着做着,又乱成一团了.要规划好界面层,至少应该遵循几条基本的原则: 保持规范性:定义好开发规范,包括 ...

  8. Jetty错误: badMessage: java.lang.IllegalStateException: too much data after closed for HttpChannelOverHttp@472adad9{r=2,c=false,a=IDLE,uri=}

    最近用Jetty跑Spring MVC接收POST请求(POST中数据很大).出现数据无法获取到的问题.如: @RequestMapping(value = "/receive", ...

  9. CentOS 6.9下的Setup工具(用于管理服务/防火墙/网络配置/验证服务)

    说明:Setup工具套件好像是CentOS下特有的用于管理服务/防火墙/网络配置等,其实就是基于命令行模式界面的GUI工具.唯一特点就是方便. 安装: #安装Setup命令工具 yum -y inst ...

  10. 正版greenvpn

    短网址 http://jsq.re(建议收藏,长期有效)长网址 https://www.greenjsq.me/网址更新页面 http://www.greenvpn.site