TCP, UDP and HTTP relations

Copyright: gitboy https://blog.csdn.net/weixin_40160543/article/details/89608040

TCP, UDP and HTTP relationships

1, TCP / IP is a protocol suite can be divided into three layers: a network layer, transport layer and application layer.

In the network layer protocol IP, ICMP protocol, ARP protocol, RARP protocol, and BOOTP protocols.

The TCP protocol and the UDP protocol in the transport layer.

Application layer FTP, HTTP, TELNET, SMTP, DNS and other protocols.

Therefore, HTTP itself is a protocol that is transmitted from a Web server Hypertext Transfer Protocol to the local browser.

TCP is a text-based network protocol TCP protocol belongs to the transport layer.

TCP and UDP are equal, belonging to the transport layer, TCP and UDP have important differences.

2, HTTP protocol is based on a request / response model. First, establish a client and a server by TCP connection and sends a request to the server, the request contains the request method, URI, and protocol version associated MIME-style message. Server responds with a status line comprising a protocol version of the message, and a failure code and the related MIME message success pattern.

HTTP / 1.0 for every HTTP request / response establish a new TCP connection, so an HTML page content and images you will need to establish short-term multiple of the TCP link contains. A TCP connection is established will require 3-way handshake.

In addition, in order to obtain appropriate transmission speed, TCP will need to spend extra time loop link (RTT). Every link is established need for such regular expenses, but it is not with the actual useful data, but to ensure the reliability of the link, so HTTP / 1.1 method of implementing sustainable links. HTTP / 1.1 will only establish a TCP link to use it repeatedly transmitting a series of request / response message, and thus reducing the number of regular link cost of the link establishment.

Here it is necessary to repeat the process about three-way handshake:

The first handshake: connection is established, the client transmits syn packets (syn = j) to the server , and enters the SYN_SENT state, waiting for the server to confirm; the SYN: synchronization sequence number (Synchronize Sequence Numbers).

Second handshake: server receives syn packets, must confirm the customer's SYN ( ACK = + J. 1), while themselves sends a SYN packet (syn = k), i.e., SYN + ACK packet, then the server into SYN_RECV state; ACK: acknowledgment character (Acknowledgement)

Third handshake: The client receives the service 's SYN + ACK packet, the server sends an acknowledgment packet the ACK ( A C K = K +. 1), this packet is sent, the client and the server into the ESTABLISHED (the TCP connection succeeds) state to complete the three-way handshake.

3. Conclusion: Although the HTTP protocol itself is a, but ultimately based on TCP. However, at present, it was being studied based on TCP + UDP mix of HTTP protocol.

Socket What is it?

Socket application layer and the intermediate software TCP / IP protocol suite to communicate abstraction layer, which is a set of interfaces. In design mode, Socket is actually a facade pattern, it is the complexity of TCP / IP protocol suite is hidden behind the Socket interface for users, a simple interface is all set, let Socket to organize data in order to comply with the specified protocol.

 

 

TCP (Transmission Control Protocol, Transmission Control Protocol)

It is a connection-based protocol, that is to say, before the official send and receive data, and the other party must establish a reliable connection. A TCP connection must go through three "dialogue" can be established, which process is very complex, we here only simple image of the introduction, as long as you do can understand this process can be. Let's look at a simple procedure three times this dialogue: Host A sends a connection request packet to the host B: "I want to send you data, can I?" This is the first dialogue; host B to host A sends agreed connection and require synchronization (synchronization is a two hosts in sending in a receipt, coordination) packets: "Yes, when did you send?" this is the second dialogue; host a then sends a data packet to identify the host B requirements synchronization: "I am now fat, then you now!" this is the third dialogue. The purpose three "dialogue" is to send and receive synchronization data packets, after three "dialogue", was officially host A sends data to the host B.

 

UDP (User Data Protocol, User Datagram Protocol)

TCP is a corresponding agreement. It is a non-connection-oriented protocol, it does not establish a connection with each other, but put the packet is sent directly to the past!

UDP apply to a transfer only a small amount of data, the reliability of less demanding application environments. For example, we often use "ping" command to test whether the TCP / IP communications between two hosts normal, in fact, "ping" the principle of command is to send a UDP packet to the other host and peer to confirm the receipt of the packet, if the data whether the packet arrived timely feedback to come back, then the network is to pass. For example, by default, a "ping" operation of transmitting packet 4 (Figure 2). As you can see, the number of packets sent four packages, package 4 is received (because the other host will send back a receipt acknowledgment packet received). This fully shows that the UDP protocol is connectionless-oriented protocol, process connection is not established. Because the process of the UDP protocol is not connected, communication is high it results; however, because of this, it is not as high as the reliability of the TCP protocol. QQ on the use of UDP message, so sometimes the situation can not receive messages appear.

 

Tcp udp protocol agreements and differences of

TCP UDP

Is connected non-connection-oriented connection-oriented

Reliable and unreliable transmission reliability

Applications where large amounts of data transfer small amounts of data

Slow fast

Guess you like

Origin blog.csdn.net/weixin_40160543/article/details/89608040