SpringBoot2 integrates WebSocket to push information from the background to the front end

The background is that the customer needs to use the Pad control page to jump in the IOC intelligent operation center, similar to the remote control of the TV. In this way, the IOC explainer can operate the control page on the Pad for display. Our solution is implemented by using WebSocket, the foreground monitors, the background opens the API to the page on the Pad, the background receives the message and pushes it to the foreground, and the foreground responds accordingly. This basically meets the requirements~

What is WebSocket?

The WebSocket protocol is a new network protocol based on TCP. It implements full-duplex (full-duplex) communication between the browser and the server - allowing the server to actively send information to the client.

WebSocket makes the data exchange between the client and the server easier, allowing the server to actively push data to the client. In the WebSocket API, the browser and the server only need to complete a handshake, and a persistent connection can be created directly between the two. Sexual connection, and two-way data transmission.

Why do you need WebSockets?

Anyone new to WebSocket asks the same question: Why do we need another protocol when we already have HTTP? What good does it bring?

The answer is simple, because the HTTP protocol has a flaw: communication can only be initiated by the client, and the HTTP protocol cannot allow the server to actively push information to the client.

For example, if we want to query the current queuing situation, we can only send a request to the server through page polling, and the server returns the query result. Polling is inefficient and wastes resources (since the connection must be kept open, or the HTTP connection is always open). because

Guess you like

Origin blog.csdn.net/qq_43842093/article/details/131024071