1. Overview
Traditional Web pages are communicated in the form of a request-the corresponding mode, each request-corresponding to a new connection. The establishment and disconnection of a connection also requires resource consumption.
WebSocket is a TCP protocol that enables two-way communication on a single connection.
This chapter includes asynchronous reading and writing of strings and binary data, selection of connection loss policies, and when to use WebSocket.
2. Main content
2.1 Asynchronous read and write string and binary data
HTTP polling is a traditional way of using a series of AJAX requests to achieve long-lasting connections on the client side (seemingly long-lasting connections).
HTTP Long Polling is a service-side technology used by clients when using AJAX to request a server. is implemented by blocking incoming requests until the current request operation is complete. In HTTP, this is not a good way, because the request-response pattern for HTTP is not designed for this scenario. And this is not a reliable way, there may be a connection interruption situation.
WebSockets is a new technology that supports duplex communication.
Not to be continued ...
The sixth chapter design program Architecture design realizes WebSocket strategy