The basic process of control point in UPnP)

Source: Internet
Author: User
1. Search for the UPnP devices on the current network. Control Point generates a multicastsocket, binds the multicast address 239.00000000250 port 1900, and then sends a search request. timetolive is set to 4 by default. The request is defined as follows in UPnP Device architecture:
M-SEARCH * HTTP/1.1
HOST: 239.00000000250: 1900
MAN: "SSDP: Discover"
MX: Seconds to delay response
St: Search target
Note that the request is based on httpmu (HTTP multicast over UDP). The above information is an HTTP header with no HTTP body, there is a blank line between the HTTP header and the HTTP body. Do not forget to send the blank line when sending it through the socket. Pay attention to this for all the messages mentioned later. After the UPnP Device receives the request, the latency is equivalent to random. nextint (MX) returns a response so that control point can have sufficient time to process requests. St is the target to be searched. If you search for all devices and services, SSDP: All is returned, if you are searching for the root device, it is UPNP: rootdevice. For example, if you use UPnP in most programs to find a gateway that supports UPnP to dynamically map ports, you can assign it to urn: schemas-UPnP-org: Device: internetgatewaydevice: 1. The following is an example. Search for all the root devices. After receiving the message, these devices must be between 0 and ~ Response returned within 3 seconds:
M-SEARCH * HTTP/1.1
HOST: 239.00000000250: 1900
MAN: "SSDP: Discover"
MX: 3
St: UPNP: rootdevice
2. The UPnP Device on the network returns a response. If the UPnP Device matches the UPnP Device to be searched, the device returns a response in the following format:
HTTP/1.1 200 OK
Cache-control: Max-age = Seconds until advertisement expires
Date: When response was generated
Ext:
Location: URL for UPnP description for root device
Server: OS/versionUPnP/1.0 Product/version
St: Search target
USN: Advertisement UUID 

Max-age indicates that no notification message is sent from the device within several seconds after the message is received, and the device is considered to have no network connection; location indicates the description file of the device, used to determine which logical devices and services the device contains. USN indicates the unique service name.

For example, for the above example to search for a message, the response returned by my ADSL is:

HTTP/1.1 200 OK
Cache-control: Max-age = 1800
Ext:
Location: http: // 10.0.0.138: 80/IgD. xml
Server: speedtouch 510 4.0.2.0.1 UPnP/1.0 (14e31y7)
St: UPNP: rootdevice
USN: UUID: UPnP-SpeedTouch510-1_00-90-D0-7F-AD-37: UPNP: rootdevice

3. The device description file is obtained to determine the device information and supported functions. Through the location attribute of the response information above, you can get a URL and get the description file of the device through the HTTP request. Note that UDP is used only for search and notification, while the rest are based on TCP. The device description file definition can be found in UPnP Device architecture. If it is longer, it will not be pasted.

For example, my ADSL returned location is http: // 10.0.0.138: 80/IgD. xml. to access this address, an XML segment is returned:

<? XML version = "1.0"?> <Root xmlns =" URN: Schemas-UPnP-org: Device-1-0"> <Specversion>  <Major> 1</Major>  <Minor> 0</Minor> </specversion>  <Urlbase> Http: // 10.0.0.138</Urlbase> <device>  <Devicetype> URN: Schemas-UPnP-org: Device: internetgatewaydevice: 1</Devicetype>  <Friendlyname> Speedtouch 510 (14e31y7)</Friendlyname>  <Manufacturer> Thomson multimedia</Manufacturer>  <Manufacturerurl> Http://www.thomson-multimedia.com</Manufacturerurl>  <Modeldescription> DSL Internet gateway</Modeldescription>  <Modelname> Speedtouch</Modelname>  <Modelnumber> 510</Modelnumber>  <Modelurl> Http://www.speedtouch.com</Modelurl>  <Serialnumber> 14e31y7</Serialnumber>  <UDN> UUID: UPnP-SpeedTouch510-1_00-90-D0-7F-AD-37</UDN>  <Presentationurl> /Index.htm</Presentationurl> <servicelist> <service>  <Servicetype> URN: Schemas-UPnP-org: Service: layer3forwarding: 1</Servicetype>  <Serviceid> URN: UPNP-org: serviceid: layer3f</Serviceid>  <Controlurl> /UPnP/control/layer3f</Controlurl>  <Eventsuburl> /UPnP/event/layer3f</Eventsuburl>  <Scpdurl> /Layer3forwarding. xml</Scpdurl>  </Service>  </Servicelist> <devicelist> ...... </devicelist> </device> </root> In the UPnP specification, a device can contain several embedded devices and services. For example, in the most commonly used Internet gateway device, the UPnP internetgatewaydevice template specifies that the root device contains the layer3 forwarding service and two embedded devices: wandevice and landevice, wandevice contains several wanconnectiondevices. 4. Get the service description provided by the device. There is a servicelist node in the device description. Each service node under this node contains a scpdurl node, which is the location of the service description file, for example, in my ADSL, the location of the layer3 forwarding service description file is/layer3forwarding. XML, and then combine the urlbase node attribute value http: // 10.0.0.138. the URL of the service description file is http: // 10.0.0.138/layer3forwarding. XML, which describes in detail the operation list provided by the Service and the corresponding parameters and parameter ranges. 5. Call the operations provided by the Service. The call is completed by sending the corresponding SOAP message to the control URL of the service. This information is defined as follows in UPnP Device architecture:
Post Path of control URLHTTP/1.1
Host: Host of control URL: Port of control URL
Content-Length: Bytes in 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:ActionnameXmlns: U = "urn: Schemas-UPnP-org: Service: servicetype: V">
<Argumentname> In Arg value </Argumentname>
Other in ARGs and their values go here, if any
</U:Actionname>
</S: Body>
</S: envelope>

For example, you can add Port ing to an IgD device to map port 5678 of the gateway to port 8765 of the Intranet 10.0.0.1. the SOAP message sent by this operation is as follows:
Post, UPnP, control, wanpppcpppoe, HTTP, 1.0
Content-Type: text/XML; charset = "UTF-8"
HOST: 10.0.0.138: 80
Content-Length: 649
Soapaction: "urn: Schemas-UPnP-org: Service: wanpppconnection: 1 # addportmapping" <? XML version = "1.0" encoding = "UTF-8"?>
<S: envelope xmlns: S = "http://schemas.xmlsoap.org/soap/envelope/" s: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/">
<S: Body>
<U: addportmapping xmlns: U = "urn: Schemas-UPnP-org: Service: wanpppconnection: 1">
<Newremotehost> </newremotehost>
<Newexternalport> 5678 </newexternalport>
<Newprotocol> TCP </newprotocol>
<Newinternalport> 8765 </newinternalport>
<Newinternalclient> 10.0.0.1 </newinternalclient>
<Newenabled> </newenabled>
<Newportmappingdescription> </newportmappingdescription>
<Newleaseduration> </newleaseduration>
</U: addportmapping>
</S: Body>
</S: envelope>
The operation is successful. The return value of the device is:
HTTP/1.0 200
Content-Type: text/XML; charset = "UTF-8"
Server: speedtouch 510 4.0.2.0.1 UPnP/1.0 (14e31y7)
Content-Length: 304
Connection: Close
Ext: <? XML version = "1.0"?>
<S: envelope xmlns: S = "http://schemas.xmlsoap.org/soap/envelope/" s: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/">
<S: Body>
<M: addportmappingresponse xmlns: M = "urn: Schemas-UPnP-org: Service: wanpppconnection: 1"> </M: addportmappingresponse>
</S: Body>
</S: envelope>

6. When some properties of the device change, if the control point subscribes to its event notification, it will send the corresponding notification to the control point. I have not thoroughly studied this part yet and need further understanding. These are just a basic control point process. For details, visit http://www.upnp.org/download/upnpda10_20000613.htm. For details, see UPnP Device architecture. Most programmers are interested in UPnP only limited to dynamic iging IgD device port, so you can go to see IgD Device specifications, the web site is http://www.upnp.org/standardizeddcps/igd.asp in the window to achieve dynamic port ing, to do a perfect point, it is best to follow the steps described in the previous article to first check whether the ICF is enabled in the window. If it is enabled, you must call the icf api to open the corresponding port on the firewall, if multicast information is intercepted by the firewall, the UPnP Device cannot be found. Many non-Microsoft applications did not pay attention to this point, which made me feel depressed for a long time when I first learned about UPnP technology, I thought that Windows 2003 could not use the UPnP Device in Windows 2003 after the support for UPnP was canceled. In the end, it was discovered that the firewall had caused a fault. Therefore, Windows does not support UPnP. If it is not supported, it is only because it cannot call the APIS provided by Microsoft :)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.