Joke Collection Website - Blessing messages - Java message push how to do websocket message push?

Java message push how to do websocket message push?

The realization principle of java message pushing websocket: In the process of websocket connection, you need to send a websocket connection request through the browser, and then the server sends a response. This process is often called "handshake". In WebSocket API, the browser and the server only need to shake hands once, and then a fast channel is formed between the browser and the server. Data can be transmitted directly between them.

In the previous message push mechanism, Ajax polling was used, and the browser automatically issued a request at a specific time interval and actively pulled back the message from the server. This method is very resource-consuming, because it is essentially an http request, which is very clumsy. WebSocket completes the handshake between browser and server. After the connection is established, the server can actively send data to the client, and the client can also send data to the server at any time.

WebSocket protocol is a new network protocol based on TCP. The full-duplex communication between the browser and the server is realized, allowing the server to send information to the client actively. You can also choose a third-party push platform, such as Aurora Push.