search

Home  >  Q&A  >  body text

javascript - Is there a way to implement HTTP long connection through JS on the client side

As mentioned in the title, I need to frequently request data from a specific server and keep establishing connection requests. This will have a lot of overhead. I wonder if there is a way for JS to implement HTTP long connections and subsequent data requests. Just keep reusing this connection channel? (ignore websocket)

高洛峰高洛峰2834 days ago584

reply all(7)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:32:44

    websocket.io

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:32:44

    http1.1 has keep-alive turned on by default. The connection will not be closed unless the server actively writes connection-close to the header. So your worries are unnecessary.
    You can check whether keep-alive is normal through the CRUL command.

    curl -Iv http://www.baidu.com 2>&1 | grep -i 'connection #0'

    When the long connection is normal, the following output will be displayed

    * Connection #0 to host www.baidu.com left intact

    Connection... left intact means that the server has not closed the connection and the client can reuse the connection.

    reply
    0
  • 黄舟

    黄舟2017-05-19 10:32:44

    If you don’t want to use websocket, use long polling.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-19 10:32:44

    The amount of messages is generally sufficient using websocket. If you want high-end, you can consider Alibaba’s open source RocketMQ

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:32:44

    websockt ?

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:32:44

    Use websocket

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:32:44

    websocket

    reply
    0
  • Cancelreply