Contact the WebSocket
In the company’s recent project, there is a function that requires the server to actively push data to the APP.
Considering that ordinary HTTP communication can only be actively pulled by the client, the server cannot actively push to the client. And then I came up with two solutions.
1. We communicated with the background that they used WebSocket, so we used WebSocket to establish a long connection between the app end and the server. So I can actually accept his message
**2. Using push, ** can also receive some messages sent from the background
Finally, I chose WebSocket and found facebook’s SocketRocket framework. Here are some records of the access process
WebSocket application scenarios
1. IM
Typical examples: wechat, QQ, etc. Of course, if the number of users is very large, it is certainly not enough to rely on WebSocket only, and major factories should also have their own optimization plans and measures. However, WebSocket is a good solution for instant messaging with small users.
2. Games (multiplayer)
Typical example: King of Glory, etc.
3. Collaborative editing (sharing documents)
When multiple people edit the same document at the same time, they can see each other’s actions in real time. In this case, WebSocket is used.
Live/video chat
High real time requirement for audio/video.
5. Stock/fund and other financial trading platforms
For stock/fund trading, the price can change from second to second.
6. IoT (Internet of Things/Smart Home)
For example, our App needs to obtain the data and status of smart devices in real time. In this case, you need to use WebSocket.
. Etc., etc.
As long as some of the “real time” requirements are relatively high, may use WebSocket.