Real-time communication (real-time) in several ways

1. ajax polling periodically send a request ajax
2. ajax long polling after sending ajax request, the server does not return until a message or a timeout, the client re-established again ajax request
3. WebSocket full duplex communication protocol in the TCP connection , requires a separate server websocket
4. SSE-server-Sent Event , also known as eventsource, based on the http protocol, lightweight, does not require additional server

Real-time communication of key points:

1. heartbeat

After the connection is established long, to detect heartbeat, ping every so often to send a message, if after a predetermined number of times, is not returned
pong response, heartbeat timeout is determined, the active connection is closed, triggering reconnection. If you receive pong, then re-initialize the timeout reconnection.

2. Close the connection

1. heartbeat timeout
2. The connection is not successfully established (e.g., a TCP connection is broken)
3. Close the server (e.g., multiport removed), this time to stop the front end of the discharge for reconnection

3. Automatic reconnection

If the shutdown occurs, then close the event, to be re-connected.
If the number of times reconnection reached, or non-return rear end reconnection identification, then no reconnection.

Guess you like

Origin www.cnblogs.com/mengff/p/12590478.html