“发现”是一个特殊的 coap 请求,用于发现已知主机的资源。
要发现主机,可以使用多播请求,但必须得到服务器的支持。
“localhost”是设备本身的地址。这样,设备将向自身发送发现请求。
我不知道 IP 地址,我想与服务器通信。
如果您不知道地址,您可以先使用“组播”请求(还需要在服务器端进行准备,请参阅MulticastServer 示例。该示例比您需要的更复杂。但也演示了原理) . 或者您需要查找该地址(android: settings -> Connections -> WLAN -> Settings-Icon :在那里您可以看到您的 IP 地址。
coapClient.discover()
发现“已知”服务器,而不是本地网络。将 localhost 替换为“californium.eclipseprojects.io”,您将获得:
</.well-known/core>
</large> Large resource
rt: [block]
sz: [1280]
</large-create> Large resource that can be created using POST method
rt: [block]
</large-post> Handle POST with two-way blockwise transfer
rt: [block]
</large-separate> Large resource
rt: [block]
sz: [1280]
</large-update> Large resource that can be updated using PUT method
rt: [block]
sz: [1280]
</link1> Link test resource
rt: [Type1, Type2]
if: [If1]
</link2> Link test resource
rt: [Type2, Type3]
if: [If2]
</link3> Link test resource
rt: [Type1, Type3]
if: [foo]
</location-query> Perform POST transaction with responses containing several Location-Query options (CON mode)
</multi-format> Resource that exists in different content formats (text/plain utf8 and application/xml)
ct: [0, 41, 50, 60]
</obs> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-large> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-non> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-pumping> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-pumping-non> Observable resource which changes every 5 seconds
rt: [observe]
obs: []
</obs-reset>
</path> Hierarchical link description entry
ct: [40]
</path/sub1> Hierarchical link description sub-resource
</path/sub2> Hierarchical link description sub-resource
</path/sub3> Hierarchical link description sub-resource
</query> Resource accepting query parameters
</seg1> Long path resource
</seg1/seg2> Long path resource
</seg1/seg2/seg3> Long path resource
</separate> Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way
</shutdown>
</test> Default test resource
</validate> Resource which varies
ct: [0]
sz: [20]
所有收到的链接都与您将发现发送到的服务器相关。