[Programming] TCP overview, programming tcp Overview

Source: Internet
Author: User

[Programming] TCP overview, programming tcp Overview

TCP Overview

1. TCP provides a connection-oriented and reliable byte stream service.

2. Two applications exchange byte streams consisting of 8-bit bytes through TCP connections.

3. Each TCP header contains the source and target port numbers, which are used to find the initiator and receiver application processes. These two values Add the source IP address and the destination IP address in the IP header to uniquely identify a TCP connection.

4. An IP address and a port number, also known as a socket, appear in the earliest TCP specification (RFC793)

 

TCP ensures reliability:

1. Application Data is divided into data blocks that TCP considers to be the most suitable for sending

2. When TCP sends a segment, it starts a timer and waits for the destination end to confirm receipt of the segment.

3. When TCP receives data from the other end of the TCP connection, it sends a confirmation message.

4. TCP will maintain its header and data validation

5. If necessary, TCP will re-sort the received data

6. TCP can also provide traffic control

 

TCP is a connection-oriented protocol.

1. Use telnet and tcpdump for mutual Testing

115.159.28.111.20.42> 10.141.14.117.http: Flags [S], seq 1784777886, win 29200,

10.141.14.117.http> 115.159.28.111.20.42: Flags [S.], seq 1181145550, ack 1784777887, win 28960,

115.159.28.111.20.42> 10.141.14.117.http: Flags [.], ack 1, win 229,

 

Seq: Sequence number (sequential number)

Ack: Acknowledge number (confirmation number)

Syn: SYN (synchronous online)

 

Host A: 115.159.28.111 host B: 10.141.14.117.http

First handshake: A sends syn = 1 and generates random seq = 1784777886

Second handshake: B sends a random generation seq = 1181145550, ack = received seq + 1 1784777887

The third handshake: A sends ack = 1,

 

TCP Header flag:

S syn synchronization sequence number

F fin completes sending

R rst Reset

P pst push

. Set to 0

 

End connection:

A special concept of TCP is half-close, which means that a TCP connection is a full-duplex (which can be sent and received at the same time) connection. Therefore, when the connection is closed, you must disable the connection between data transmission and data transmission. The client sends a TCP packet whose FIN is 1 to the server, and then the server returns an ACK packet to the client, and sends a FIN packet. When the client replies the ACK packet (four handshakes ), the connection is over.

 

Client status migration:

CLOSED-> SYN_SENT-> ESTABLISHED-> FIN_WAIT_1-> FIN_WAIT_2-> TIME_WAIT-> CLOSED

Server Status migration:

CLOSED-> LISTEN-> SYN received-> ESTABLISHED-> CLOSE_WAIT-> LAST_ACK-> CLOSED

 

Persistent connection: Multiple data packets can be sent continuously on a single connection. If no data packet is sent during connection persistence, both parties need to send a link detection packet.

Transient connection: A connection is established when both parties have data interaction. After data is sent, the connection is disconnected, that is, only one service is sent each time.

 

Ulimit-

Ulimit-n is used to limit the maximum number of file descriptors that a process can open. Because any device is a file in linux and the communication interface is also responsible for a special interface file, the maximum concurrency of tcp links in linux is also limited by this value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.