HTTP 和 COAP 之间的主要区别是什么?

What are the major differences between HTTP and COAP?

HTTP主要用于浏览网页。 Coap 是用于 IoT 或 WSN 的 HTTP 的简化版本。 COAP虽然是基于UDP的,但是应该有ACK报文来模拟TCP。由于 COAP 比 HTTP 更简单,它具有更低的延迟和更少的功耗。

那么,为什么浏览器和网络服务器不使用 COAP 代替 HTTP?鉴于前面的争论,COAP是否有望完全取代HTTP?这只是时间问题吗?是否有仅 HTTP 支持的功能?

If coap is more efficient, can I say that http is useless in the future if we replace them to coap?

行业计划是通过迁移到 HTTP/2 来改进 HTTP,并且 HTTP/2 包括(在其他功能中)header 压缩,这应该会为您带来与 CoAP 类似的好处。

虽然现在大多数网络服务器和一些浏览器已经支持 HTTP/2,但 AFAIK 没有浏览器或任何服务器支持 CoAP。 TLS 与 DTLS 也一样。

Are there features coap cannot support but http can?

正如您所说,HTTP 是基于 TCP 的,而 CoAP 是基于 UDP 的。 UDP 要求您每隔几秒发送一次 UDP ping 以保持 NAT/Firewall 连接打开,而在 TCP 中通常只需要每 15 分钟左右发送一次。 因此,如果您需要保持连接打开(例如对于推送技术),那么 CoAP 的效率低于 HTTP(和 HTTP/2)。

CoAP 从未打算取代 HTTP,而它似乎 "emulate" http,只是因为它遵循 REStful 范式。 CoAP 旨在作为设备的应用层,更具体地说是为约束设备设计的。

选择 REStful 设计也是为了促进通过 http 的代理操作(在 RFC 中建议这样做)。但同样从未打算取代 HTTP。

CoAP 是在考虑少量资源的情况下构建的。 CoAP 的小 header 和不同的功能已到位,以确保约束设备具有标准意味着可以在 Internet 上通信。

HTTP 和 CoAP 各有各的用途。

CoAP 针对 资源受限网络 和典型的 IoTM2M 设备进行了优化应用程序。它使用比 HTTP 更少的资源,可以为 WSN、IoT 和 M2M 通信中的通信提供环境。它不是用来替代 HTTP 的。

HTTP有不同的应用场景,而CoAP有不同的应用场景。 HTTP 主要设计用于功率和其他限制不是重要问题的 Internet 设备。 HTTP 比 CoAP 更可靠,因为它使用 TCP。

CoAP 和 HTTP 可用于不同的目的。 CoAP 已经针对 IoT 和 M2M 环境实现,换句话说,使用 UDP 发送短消息。例如:

A typical CoAP exchange consists of 2 messages, i.e., a request and a response. In contrast, an HTTP request first requires the client to establish a TCP connection and later terminate it. This results in at least 9 messages for only one request [11]. Note that this argument is not necessarily true for large payloads. After TCP’s slow-start phase, it is able to send multiple packets at once and acknowledge all of them with a single acknowledgement. CoAP’s blockwise transfer [8] though, requires an acknowledgement for each block and leads to more messages and higher transfer time. Since we expect the majority of CoAP messages to be rather short, this is of less importance. However, CoAP’s blockwise mechanism allows a constrained server to not only receive but also process a large request block-by-block. This would not be possible if we used HTTP and TCP. (Scalability for IoT CLoud Services by Martin Lanter)

实际上,Firefox 可以使用 Copper(CU) 插件支持 CoAP。 ;)