SSDP協議-樣本

來源:互聯網
上載者:User

近來在研究SSDP,Simple Service Discovery Protocol (簡單服務發現協議)。

這是用來實現無配置,自發現區域網路內部服務的協議。

由IPv4下有固定的239.255.255.250:1900這一固定的地址來負責多播資料。

不過,從我的學習經曆來說,要啃這種東西,最好的方法還是用例子搞懂名詞,並實踐一次。其實SSDP協議的請求就三種: byebye, alive, discovery byebye請求

NOTIFY * HTTP/1.1Host: 239.255.255.250:1900NT: someunique:idscheme3NTS: ssdp:byebyeUSN: someunique:idscheme3
NOTIFY 通知所有廣播域的機器 HOST 值是固定的(IPv4),算是協議的一部分 NT (Notification Type)這個是GENA的定義,即通知類型,值一般是當前裝置的類型 NTS (Notification Sub-Type)通知子類型,如果要遵守SSDP,這個值就代表了請求的類型,但是為什麼NTS和NT搞混了呢……協議中寫得非常明白 

5.3.5. Shouldn’t the NT and NTS values be switched?

Yes, they should. Commands such as ssdp:alive and ssdp:byebye should

be NT values and the service type, where necessary, should be the

NTS. The current mix-up is a consequence of a previous design where

the NT header was used in a manner much like we use the USN today.

This really needs to change.

USN 這個裝置的UUID,防止裝置的IP或者網路環境改變後,串連至錯誤的裝置。 alive(服務上線/廣播存活/心跳包)

NOTIFY * HTTP/1.1HOST: 239.255.255.250:1900CACHE-CONTROL: max-age=100LOCATION: http://10.5.4.81:49155/TxMediaRenderer_desc.xmlNT: upnp:rootdeviceNTS: ssdp:aliveUSN: uuid:001e4fd3fa0e0000_MR::upnp:rootdevice
CACHE-CONTROL說明這個裝置狀態至少在100秒內不會到期,到期時,所有裝置就必須要重新整理這資訊,如果得不到新的資料,則認為此裝置不可用。如果不提供CACHE-CONTROL或者EXPIRES,此裝置的資訊將不允許緩衝,逾時機制由接受端決定 LOCATION此裝置的控制點或描述檔案所在地 discovery請求
M-SEARCH * HTTP/1.1Host:239.255.255.250:1900ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1Man:"ssdp:discover"MX:3
M-SEARCH 說明這是強制的搜尋方法(由Mandatory Extensions in 
HTTP中的Mandatory HTTP Requests確定) ST (search term)搜尋條件,指明需要搜尋的裝置,可以是類型,服務,甚至是UUID,至於怎麼回應嘛……那是服務端的事了 Man M-SEARCH請求必須帶的資料項目,值必須為“ssdp:discover” MX 優先順序,數字越高,優先順序越低

服務發現的現實流程

+---------+ +---------+               +-----------+            | Client  | | Server  |               | Multicast |            +---------+ +---------+               +-----------+---------------\ |           |         || Initialized  |-|           |         |---------------- |           |         ||           |         || discovery |         ||------------------------------------->||           |         ||           |          Client wants ST ||           |< ------------------------||           | -------------------\     ||           |-| In discovery ST? |     ||           | --------------------     ||           |         ||           | (In ST) alive            ||           |------------------------->||           |         ||           |           Here is Server ||< ------------------------------------||           |         |

好了,這個協議就這麼Simple~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.