What is persistent connection?
In fact, persistent connections are relative to common short connections, that is, to maintain the connection between the client and the server for a long time.
The common short connection procedure is as follows:
Connection-data transmission-close connection;
The persistent connection is usually:
Connection-data transmission-keep connection... -Close connection;
This requires that long connections send data packets regularly when there is no data communication to maintain the connection status. Short connections can be closed directly when there is no data transmission.
When can I use persistent connections or short connections?
Persistent connections are mainly used inMinorityClient and serverFrequentCommunication, because in this case, if a short connection is used for frequent communication, a socket error will often occur, and frequent creation of socket connections is also a waste of resources.
However, for the server, persistent connections consume certain resources and require dedicated threads (process management can be used in UNIX) to maintain the connection status.
In short, the choice of persistent connection and short connection depends on the situation.