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)
为情所困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.
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