iOS,什么应用或者场景下需要使用socket编程?
大家讲道理
大家讲道理 2017-04-18 09:33:47
0
2
303

一些应用只是使用了HTTP编程,也就是只用了AFNetworking。 但是听说IM类的应用需要使用到socket,是为什么呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
左手右手慢动作

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template