http is one-time use, and socket can realize long connection. Socket will be used if a round-trip network request cannot solve the problem. For example, when refreshing Moments and downloading pictures in WeChat, HTTP requests are used. When receiving messages, we don’t know when the messages will come, so we set up a socket to monitor them all the time. When sending messages, HTTP is used more frequently and requires a new handshake every time. Sockets are used for audio and video calls, resumed transmissions, etc. In theory, synchronization messages after starting WeChat or disconnecting and reconnecting can use http to request unreceived messages, but for many reasons, sockets are also used.
Of course, what I mentioned above is only the most basic reason. There are many reasons why http cannot be implemented using socket. Everything that http can achieve, socket can achieve, because http is just an application scenario protocol of socket via tcp.
IM is mostly a set of transmission protocols developed by itself based on sockets, similar to http, but developed for its own business.
In order to obtain the user's login status, the IM application server must continuously send "heartbeat packets" to confirm that the user is online and the user's network status. If HTTP is used, there will be too much redundant information (HEADER, CONTENT-TYPE, STATUS) and the like. .
Many IM applications implement their own network protocols for security or data compression.
http is one-time use, and socket can realize long connection. Socket will be used if a round-trip network request cannot solve the problem.
For example, when refreshing Moments and downloading pictures in WeChat, HTTP requests are used. When receiving messages, we don’t know when the messages will come, so we set up a socket to monitor them all the time. When sending messages, HTTP is used more frequently and requires a new handshake every time. Sockets are used for audio and video calls, resumed transmissions, etc. In theory, synchronization messages after starting WeChat or disconnecting and reconnecting can use http to request unreceived messages, but for many reasons, sockets are also used.
Of course, what I mentioned above is only the most basic reason. There are many reasons why http cannot be implemented using socket.
Everything that http can achieve, socket can achieve, because http is just an application scenario protocol of socket via tcp.
IM is mostly a set of transmission protocols developed by itself based on sockets, similar to http, but developed for its own business.
In order to obtain the user's login status, the IM application server must continuously send "heartbeat packets" to confirm that the user is online and the user's network status. If HTTP is used, there will be too much redundant information (HEADER, CONTENT-TYPE, STATUS) and the like. .
Many IM applications implement their own network protocols for security or data compression.