What are "persistent connections" and "Transient connections "?
Interpretation 1
The so-called persistent connection means that the connection is maintained no matter whether or not it is used after a socket connection is established, but the security is poor;
The so-called short connection means that the connection is closed immediately after the socket connection is established and the data is sent and received. Generally, banks use short connections.
Interpretation 2
Persistent connection means to keep the connection in TCP-based communication regardless of whether data is sent or received.
Short connections are only connected when data is transmitted. After the customer-server communication or data transmission is complete, the connection is closed.
Explanation 3
The concept of persistent connection and short connection seems to have only been mentioned in the mobile CMPP protocol, but not in other places.
Communication Method
There are two connection methods for each network element: persistent connection and short connection. A persistent connection means that multiple data packets can be sent continuously over a TCP connection. If no data packet is sent during TCP connection persistence, both parties need to send a detection packet to maintain this connection. A short connection is a TCP connection established when both parties have data interaction. After the data is sent, the TCP connection is disconnected, that is, only one CMPP message is sent each time.
At this stage, ismg must use persistent connections. We recommend that you use persistent connections between the SP and ismg.
Interpretation 4
Short connection: for example, HTTP only supports connection, request, and close. If the server does not receive a request within a certain period of time, the connection is closed.
Persistent connection: Some services need to be connected to the server for a long time, such as CMPP. They generally need to be maintained online by themselves.
HTTP protocol length and short connection
1. persistent connection and short connection:
Persistent connection: the client establishes a connection with the server. After the connection is established, the client continues to send and receive packets.
In this mode, communication connections always exist. This method is usually used for P2P communication.
Short connection: the client and server communicate with each other only when sending and receiving packets. The connection is closed immediately after the transaction is completed.
This method is usually used for one-to-multiple-point communication. C/s communication.
Ii. Operation Process of persistent connection and short connection:
The procedure of transient connection is as follows:
Establish connection -- data transmission -- close connection... establish connection -- data transmission -- close connection
The procedure for persistent connection is:
Establish connection -- data transmission... (keep connection)... data transmission -- close connection
Iii. Time to use persistent connection and short connection:
Persistent connections: Short connections are often used for frequent operations, point-to-point communication, and the number of connections cannot be too large.
Three handshakes are required for the establishment of each TCP connection, and four handshakes are required for the disconnection of each TCP connection.
If a connection needs to be established for each operation, the processing speed will be reduced. Therefore, after each operation, you can directly send data during the next operation without establishing a TCP connection. For example, if a database is connected with a persistent connection, frequent communication with a short connection may cause a socket error, and frequent socket creation is also a waste of resources.
Short connection: HTTP Services of Web sites generally use short connections. Because persistent connections consume certain resources for servers. Connections to thousands or even hundreds of millions of clients such as web sites frequently use short connections to save some resources. Imagine how much pressure the server would be under if we were using persistent connections with thousands of users and each user had a connection. Therefore, a large number of concurrent connections are required, but each user does not need to perform frequent operations. In short, the choice of persistent connection and short connection depends on the needs.
4. Sending and receiving methods:
1. asynchronous: messages are sent and received separately and are independent from each other. This method can be divided into two situations:
Asynchronous duplex: In the same program, two different sub-processes are responsible for sending and transmitting data respectively.
Asynchronous Ticket: two different programs are used for sending and picking.
2. Synchronization: send and receive packets synchronously, that is, the packets are waiting for the return packets after being sent. The timeout issue needs to be considered in the synchronization mode. Imagine that we cannot wait infinitely after sending the message, so we need to set a wait
. Beyond the waiting time, the sender no longer waits for the read Response Message. Direct notification timeout is returned.
5. Message format:
As there are more diverse communication message formats, you must design functions for receiving and sending corresponding read/write packets.
Blocking and non-blocking Modes
1. Non-blocking mode: The READ function does not stop reading. If no message is received, wait for a period of time to return the response. In this case, you need to specify the timeout time.
2. Blocking Mode: If no message is received, the READ function remains in the waiting state and knows that the message has arrived.
Cyclic read/write mode
1. One direct read/write packet: All or all sent bytes are read or sent separately at one time during one message receiving or sending operation.
2. do not specify the length of cyclic read/write: This version occurs in the transient connection process and is subject to network routing and other restrictions, A long packet may be divided into many packets during network transmission. One read may not be able to read all the packets. This requires reading packets cyclically until the packets are read.
3. Cyclic read/write with the length of the packet header: in this case, it is generally in a persistent connection, because there is no condition in the persistent connection to determine when the cyclic read/write ends. The Length header must be added. The READ function first reads the length of the packet header and then reads the packet according to the length. In actual situations, the Header Format is often different. If it is a non-ASCII packet header, common ASCII message headers must also be converted:
1. ASCII code of n Bytes.
2. n Bytes of BCD code.
3. A network integer of n Bytes.
The above are several typical read/write messages. You can provide some typical API read/write functions in advance with the communication mode template. Of course, in practice, you may have to write a read/write API that matches the recipient's message format. in actual situations, we often need to connect our own system with others' systems. With the above templates and APIs, we can say that there is no problem in connecting communication programs in any way.