一次性搞懂长轮询、短轮询、SSE、websocket区别

[[toc]]

http的4种推送技术

  1. 客户端轮询:传统意义上的短轮询(Short Polling)
  2. 服务器端轮询:长轮询(Long Polling)
  3. 单向服务器推送:Server-Sent Events(SSE)
  4. 全双工通信:WebSocket

图中

  • 每个箭头代表的是 http 连接
    Snipaste_2023-10-29_16-51-23

tcp的长连接和短连接

http keep-alive

是什么?

  • 本质: HTTP长连接,复用TCP连接
  • 服务端返回 response 后,不关闭TCP连接;
  • 客户端接收完 response 后,不关闭TCP连接,发送下个request时重用该连接

keep-alive 模式怎么开启

  • http1.0 和 http1.1 都可以实现长连接
  • 1.0 默认关闭,需在请求头加入"Connection: Keep-Alive",才能启用Keep-Alive;
  • 1.1 默认启用Keep-Alive,如果加入"Connection: close ",才关闭。

如何查看连接是http 1.0 还是

猜你喜欢

转载自blog.csdn.net/qubes/article/details/134286008