The server pushes SSE technology

SSE (Server-Sent Events) is a technology used to enable the server to actively push data to the client, also known as " event stream " (Event Stream). Based on the HTTP protocol, it takes advantage of its long connection feature to establish a persistent connection between the client and the server, and through this connection, the real-time data push from the server to the client is realized.

Based on the HTTP protocol, SSE uses its persistent connection feature to send an HTTP request to the server through the browser to establish a persistent connection. WebSocket, on the other hand, establishes a new TCP connection through a special upgrade protocol (HTTP/1.1 Upgrade or HTTP/2), which is different from traditional HTTP connections.

SSE can transmit data in text and binary formats, but only supports one-way data flow, that is, data can only be pushed from the server to the client. WebSocket supports bidirectional data flow, client and server can send messages to each other, and there is no message size limit.

The implementation of SSE is relatively simple and is based on the HTTP protocol, which is not much different from ordinary web applications, so the risk is relatively low. WebSocket requires additional security measures (such as SSL/TLS encryption) to ensure the security of data transmission to avoid eavesdropping and tampering, otherwise it may cause security risks.

Applicable to the scene

The data returned by chatGPT is the SSE technology used

Real-time data large screen If you just need to display real-time data, you can use SSE technology instead of using webSocket

Guess you like

Origin blog.csdn.net/apple_52957499/article/details/131356212