Is there a way to send CoAP commands using JavaScript?

非 Y 不嫁゛ 提交于 2019-12-05 12:28:59

Unfortunately this is not directly possible. Web browsers do not provide any JavaScript API for UDP sockets for security reasons.

If you need an in-browser app to communicate to a device via a CoAP interface, you may need to provide an intermediary service. For example, you could create a web service that is accessible via HTTP, and acts as a translator to CoAP.

Note that node.js does support UDP connections, and could be used to send CoAP messages. However, it is a server-side technology, and cannot be used in the browser. It could be used to build such a translator service; but would not be required.

Also, it appears that "Chrome Apps", which are based on HTML5 and JavaScript, but are distinctly different from web pages, do have access to UDP Sockets.

It is possible when using CoAP over TCP/IP or a CoAP-HTTP proxy, like Californium, jCoAP, SmartServiceProxy or Squid with CoAP-HTTP.

There is also a partial JavaScript implementation of CoAP - JSCoAP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!