DNLA自学(一) UPnP设备发现

报文说明:

 
客户端 搜索报文:
 
M-SEARCH * HTTP/1.1               //请求头 不可改变
MAN: "ssdp:discover"                //设置协议查询的类型,必须是:ssdp:discover
MX: 5                                         //设置设备响应最长等待时间,设备响应在0和这个值之间随机选择响应延迟的值。这样可以为控制点响应平衡网络负载。
HOST: 239.255.255.250:1900    //设置为协议保留多播地址和端口,必须是:239.255.255.250:1900(IPv4)或FF0x::C(IPv6
ST: upnp:rootdevice                  设置服务查询的目标,它必须是下面的类型:
                                //ssdp:all  搜索所有设备和服务 
                           //upnp:rootdevice  仅搜索网络中的根设备 
                           //uuid:device-UUID  查询UUID标识的设备 
                           //urn:schemas-upnp-org:device:device-Type:version  查询device-Type字段指定的设备类型,设备类型和版本由UPNP组织定义。 
                           //urn:schemas-upnp-org:service:service-Type:version  查询service-Type字段指定的服务类型,服务类型和版本由UPNP组织定义。
 
 
服务器响应:
HTTP/1.1 200 OK    //响应头
CACHE-CONTROL: //max-age指定通知消息存活时间,如果超过此时间间隔,控制点可以认为设备不存在 (如:max-age=1800)
DATE:                     //指定响应生成的时间
EXT:                        //向控制点确认MAN头域已经被设备理解(通常都是空)
LOCATION:            //包含根设备描述得URL地址  device 的webservice路径(如:http://127.0.0.1:2351/1.xml)
SERVER:                 //包含操作系统名,版本,产品名和产品版本信息( 如:Windows NT/5.0, UPnP/1.0)
ST:                         //内容和意义与查询请求的相应字段相同(如:upnp:rootdevice)
USN:                     //表示不同服务的统一服务名,它提供了一种标识出相同类型服务的能力。如:
                             //根/启动设备 uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::upnp:rootdevice
                             //连接管理器   uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::urn:schemas-upnp-org:service:ConnectionManager:1
                            //内容管理器 uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::urn:schemas-upnp-org:service:ContentDirectory:1                                    
服务器定时发送:
 
NOTIFY * HTTP/1.1   //头 
NT:                            //在此消息中,NT头必须为服务的服务类型。(如:upnp:rootdevice)
HOST:                       //设置为协议保留多播地址和端口,必须是:239.255.255.250:1900(IPv4)或FF0x::C(IPv6
NTS:                          //表示通知消息的子类型,必须为ssdp:alive
LOCATION:               //包含根设备描述得URL地址  device 的webservice路径(如:http://127.0.0.1:2351/1.xml
CACHE-CONTROL:   //max-age指定通知消息存活时间,如果超过此时间间隔,控制点可以认为设备不存在 (如:max-age=1800)
SERVER:                    //包含操作系统名,版本,产品名和产品版本信息( 如:Windows NT/5.0, UPnP/1.0)
USN:                         //表示不同服务的统一服务名,它提供了一种标识出相同类型服务的能力。如:
                                 //根/启动设备 uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::upnp:rootdevice
                                 //连接管理器   uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::urn:schemas-upnp-org:service:ConnectionManager:1
                                 //内容管理器 uuid:f7001351-cf4f-4edd-b3df-4b04792d0e8a::urn:schemas-upnp-org:service:ContentDirectory:1  
服务器结束:
NOTIFY * HTTP/1.1 //头
HOST:                    //设置为协议保留多播地址和端口,必须是:239.255.255.250:1900(IPv4)或FF0x::C(IPv6
NTS:                      //表示通知消息的子类型,必须为ssdp:byebye
USN:                      //同上
 

具体例子:

客户端发起

客户端请求:
 
M-SEARCH * HTTP/1.1
ST: upnp:rootdevice
MAN: "ssdp:discover"
HOST: 239.255.255.250:1900
MX: 10
 
 
服务器响应:
 
HTTP/1.1 200  OK
ST:  upnp:rootdevice
CACHE-CONTROL:  max-age=1800
EXT: 
USN:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::upnp:rootdevice
SERVER:  Windows NT/5.0, UPnP/1.0
LOCATION:  http://192.168.0.106:44552/
Content-Length: 0
 
HTTP/1.1 200  OK
ST:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49
CACHE-CONTROL:  max-age=1800
EXT: 
USN:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49
SERVER:  Windows NT/5.0, UPnP/1.0
LOCATION:  http://192.168.0.106:44552/
Content-Length: 0
 
 
HTTP/1.1 200  OK
ST:  urn:schemas-upnp-org:device:MediaServer:1
CACHE-CONTROL:  max-age=1800
EXT: 
USN:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:device:MediaServer:1
SERVER:  Windows NT/5.0, UPnP/1.0
LOCATION:  http://192.168.0.106:44552/
Content-Length: 0
 
 
HTTP/1.1 200  OK
ST:  urn:schemas-upnp-org:service:ConnectionManager:1
CACHE-CONTROL:  max-age=1800
EXT: 
USN:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:service:ConnectionManager:1
SERVER:  Windows NT/5.0, UPnP/1.0
LOCATION:  http://192.168.0.106:44552/
Content-Length: 0
 
HTTP/1.1 200  OK
ST:  urn:schemas-upnp-org:service:ContentDirectory:1
CACHE-CONTROL:  max-age=1800
EXT: 
USN:  uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:service:ContentDirectory:1
SERVER:  Windows NT/5.0, UPnP/1.0
LOCATION:  http://192.168.0.106:44552/
Content-Length: 0
 

服务器启动时发起

 
注释:
1、MediaServer/DMS服务器 因包含ContentDirectory和ConnectionManager基础服务。
2、以下报文共发了2次
根服务器:
NOTIFY * HTTP/1.1
NT: upnp:rootdevice
HOST: 239.255.255.250:1900
NTS: ssdp:alive
LOCATION: http://192.168.0.106:44552/
CACHE-CONTROL: max-age=1800
USN: uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::upnp:rootdevice
SERVER: Windows NT/5.0, UPnP/1.0
Content-Length: 0
 
连接管理服务:
NOTIFY * HTTP/1.1
NT: urn:schemas-upnp-org:service:ConnectionManager:1
HOST: 239.255.255.250:1900
NTS: ssdp:alive
LOCATION: http://192.168.0.106:44552/
CACHE-CONTROL: max-age=1800
USN: uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:service:ConnectionManager:1
SERVER: Windows NT/5.0, UPnP/1.0
Content-Length: 0
 
内容管理服务: 
NOTIFY * HTTP/1.1
NT: urn:schemas-upnp-org:service:ContentDirectory:1
HOST: 239.255.255.250:1900
NTS: ssdp:alive
LOCATION: http://192.168.0.106:44552/
CACHE-CONTROL: max-age=1800
USN: uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:service:ContentDirectory:1
SERVER: Windows NT/5.0, UPnP/1.0
Content-Length: 0
 
媒体服务器:
NOTIFY * HTTP/1.1
NT: urn:schemas-upnp-org:device:MediaServer:1
HOST: 239.255.255.250:1900
NTS: ssdp:alive
LOCATION: http://192.168.0.106:44552/
CACHE-CONTROL: max-age=1800
USN: uuid:ae1f51a9-9414-47cf-bded-199ffb493e49::urn:schemas-upnp-org:device:MediaServer:1
SERVER: Windows NT/5.0, UPnP/1.0
Content-Length: 0
 




posted @ 2013-04-02 11:16  田径  阅读(3049)  评论(0编辑  收藏  举报
我的开源的地址https://github.com/tianjing/ 大家踊跃拍砖共同成长,拍砖的同时记得附上意见或者建议。!!谢谢 谢谢