Small tips: TCP three-way handshake, long connection, short connection, SPDY protocol

When TCP protocol communication network, before the actual write operation, a connection must be established between the Client and the server, when the write operation is completed, the two sides are no longer needed they are attached may release the connection, the connection is established three-way handshake is required, they need to release fourth wave, so that each is required to establish a connection resource consumption and time consumption.

TCP three-way handshake

Three-way handshake to establish a connection:

  • The first handshake: a client sends syn packets (seq = x) to the server, and enters SYN_SEND state, waiting for the server to confirm;
  • Second handshake: server receives syn packets, must confirm the customer SYN (ack = x + 1), while themselves sends a SYN packet (seq = y), i.e., SYN + ACK packet, then the server enters a state SYN_RECV;
  • Third handshake: the client receives the SYN + ACK packet to the server, the server sends an acknowledgment packet ACK (ack = y + 1), this packet is sent, the client and server into the ESTABLISHED state, complete the three-way handshake.

Bag handshake does not include the transfer of data, after three-way handshake is completed, the client and server before the official start transferring data. Ideally, TCP connection, once established, before any party in the communication of the two parties take the initiative to close the connection, TCP connection will be kept down.

The classic three-way handshake diagram:

The classic four-way handshake close map:

TCP long connection

The so-called long connection, refers to a TCP connection can continuously send multiple packets in a TCP connection during the hold, if there is no data packet is sent, the two sides need to send test kits to maintain this connection, the general need to maintain their own online (RST does not occur package and four wave).

→ → data transfer connection to remain connected (heartbeat) → holding → data transfer connection (heartbeat) → → ...... close the connection (TCP connection to a communication channel a plurality of read and write).

This requires long connection when no data communication, transmission timing of a packet (heartbeat), to maintain the connection state.

TCP short connection

Short connection is a communication when the two sides exchange data on the establishment of a TCP connection, the data transmission is complete, then disconnect the TCP connection (management is relatively simple, existing connections are useful connection, no additional control means) .

→ → data transfer connection to close the connection.

 SPDY protocol

 SPDY protocol is an application layer protocol proposed by Google Transmission Control Protocol (TCP), the load time is shortened by compression, multiplexing, and priority. The agreement is a more rapid content delivery protocol.

SPDY protocol target is to optimize the performance of HTTP protocol, through compression, multiplexing and priority technology to shorten page load time and increase security. SPDY protocol core idea is to minimize the number of TCP connections and for HTTP semantics without making too much modification (for example, HTTP GET and POST message format remains the same), basically compatible HTTP protocol.

Guess you like

Origin www.cnblogs.com/moqiutao/p/11079973.html