当然如果作为一个控制点,也有权限搜索自己感兴趣的设备。搜的时候控制点自己不知道有没有自己感兴趣的设备。同样这也是通过多播的形式,当世界的另一端乖妹子听到了这个信息,那么就会以单独的形式应答,这就是单播响应。就相当于面试一样,公司要找一个美工妹子,发布一个广告,添加要求福利待遇,然后留个邮箱,感兴趣的美工妹子们就会发简历到这个邮箱。人可以喊,公司可以登招聘广告,但是设备不可以。那么设备是怎么做到的,设备是依托于ssdp(Simple Service Discovery Protocol)简单服务发现协议,这个协议类似定义了怎么喊,喊的格式,怎么登招聘广告,广告的格式是怎么样的。如下所示:
<?xml version="1.0"?><rootxmlns="urn:schemas-upnp-org:device-1-0"><specVersion><major>1</major><minor>0</minor></specVersion><URLBase>base URL for all relative URLs</URLBase><device><deviceType>urn:schemas-upnp-org:device:deviceType:v</deviceType><friendlyName>short user-friendly title</friendlyName><manufacturer>manufacturer name</manufacturer><manufacturerURL>URL to manufacturer site</manufacturerURL><modelDescription>long user-friendly title</modelDescription><modelName>model name</modelName><modelNumber>model number</modelNumber><modelURL>URL to model site</modelURL><serialNumber>manufacturer's serial number</serialNumber><UDN>uuid:UUID</UDN><UPC>Universal Product Code</UPC><iconList><icon><mimetype>image/format</mimetype><width>horizontal pixels</width><height>vertical pixels</height><depth>color depth</depth><url>URL to icon</url></icon>
XML to declare other icons, if any, go here
</iconList><!--以上是信息描叙,以下是能力行为描叙--><serviceList><service><serviceType>urn:schemas-upnp-org:service:serviceType:v</serviceType><serviceId>urn:upnp-org:serviceId:serviceID</serviceId><SCPDURL>URL to service description</SCPDURL><controlURL>URL for control</controlURL><eventSubURL>URL for eventing</eventSubURL></service>
Declarations for other services defined by a UPnP Forum working committee (if any)
go here
Declarations for other services added by UPnP vendor (if any) go here
</serviceList><!--以上是能力行为描叙,以下是从设备描述--><deviceList>
Description of embedded devices defined by a UPnP Forum working committee (if any)
go here
Description of embedded devices added by UPnP vendor (if any) go here
</deviceList><presentationURL>URL for presentation</presentationURL></device></root>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
这里需要值得注意的是:能力行为的描述也就是:
<service><serviceType>urn:schemas-upnp-org:service:serviceType:v</serviceType><serviceId>urn:upnp-org:serviceId:serviceID</serviceId><SCPDURL>URL to service description</SCPDURL><controlURL>URL for control</controlURL><eventSubURL>URL for eventing</eventSubURL></service>
<?xml version="1.0"?><scpdxmlns="urn:schemas-UPnP-org:service-1-0"><!--要求upnp的架构版本--><specVersion><major>1</major><minor>0</minor></specVersion><!--action列表--><actionList><action><!--action名称--><name>actionName</name><!--参数列表--><argumentList><argument><!--参数名称--><name>formalParameterName</name><!--参数是入参还是出参--><direction>in xor out</direction><retval /><!--必须是一个状态变量的名称,文档后面状态变量的表会对应其类型和取值范围等,就类似类中的某个属性值的名称--><relatedStateVariable>stateVariableName</relatedStateVariable></argument></argumentList></actionList><!--状态变量的表--><serviceStateTable><!--sendEvents标识变量值发生变化需不需要回调通知状态改变--><stateVariablesendEvents="yes"><!--状态变量的名称--><name>variableName</name><!--状态变量的数据类型--><dataType>variable data type</dataType><!--状态变量的初始化的值--><defaultValue>default value</defaultValue><!--状态变量的允许设置的值--><allowedValueList><allowedValue>enumerated value</allowedValue>
Other allowed values defined by UPnP Forum working committee (if any) go here
</allowedValueList></stateVariable><stateVariablesendEvents="yes"><name>variableName</name><dataType>variable data type</dataType><defaultValue>default value</defaultValue><!--状态变量的允许设置的值范围--><allowedValueRange><minimum>minimum value</minimum><maximum>maximum value</maximum><step>increment value</step></allowedValueRange></stateVariable>
Declarations for other state variables defined by UPnP Forum working committee
(if any) go here
Declarations for other state variables added by UPnP vendor (if any) go here
</serviceStateTable></scpd>
POST path of control URL HTTP/1.1
HOST: host of control URL:port of control URL
CONTENT-LENGTH: bytesin body
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:serviceType:v#actionName"
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
<argumentName>in arg value</argumentName>
other in args and their values go here, ifany
</u:actionName>
</s:Body>
</s:Envelope>
HTTP/1.1200 OK
CONTENT-LENGTH: bytes inbody
CONTENT-TYPE: text/xml; charset="utf-8"
DATE: when response was generated
EXT:
SERVER: OS/version UPnP/1.0 product/version
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:actionNameResponse xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
<argumentName>out arg value</argumentName>
other out args and their values go here, if any
</u:actionNameResponse>
</s:Body>
</s:Envelope>