The difference between TCP, UDP, HTTP, HTTPS

Network divided up by the following:

Physical Layer ---

data link layer---

The network layer - IP protocol

The transport layer - TCP protocol

Session layer -

Presentation layer and application layer - HTTP protocol

1, TCP / IP connection

TCP Transmission Control Protocol, provides a universal protocol for reliable data transmission

The phone is able to use the phone because networking is the underlying implementation of the TCP / IP protocol, you can make phone terminal TCP connection is established via a wireless network. TCP protocol can provide an interface to the upper network, the network data transmission upper layer built on top of "non-discriminatory" network.

Establish a TCP connection to go through, "three-way handshake":

 
The first handshake: a client sends syn packets (syn = j) 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 = j + 1), while themselves sends a SYN packet (syn = k), 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 = k + 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. When disconnected from the server and client sides can initiate a request to disconnect the TCP connection, disconnection process to go through "handshake" (writing process is not fine, that is, the server and client interaction, and ultimately determine the disconnection)

2, UDP protocol

UDP User Datagram Protocol is a connectionless-oriented protocol. With this protocol does not require two applications to establish a connection. UDP protocol does not provide error recovery, data retransmission is not provided, so that the poor security protocol for transferring data.
(1), TCP connection-oriented (e.g., dial-up connection is established first call); the UDP is connectionless, i.e. without establishing a connection before sending data
(2), TCP provides reliable service. In other words, the data transfer connection of TCP, error-free, not lost, not repeat, and arrive out of order; UDP best effort, that does not guarantee reliable delivery

 

 

 

 3, HTTP connection

 
HTTP协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用。
 
HTTP连接最显著的特点是客户端发送的每次请求都需要服务器回送响应,在请求结束后,会主动释放连接。从建立连接到关闭连接的过程称为“一次连接”。
 
1)在HTTP 1.0中,客户端的每次请求都要求建立一次单独的连接,在处理完本次请求后,就自动释放连接。
2)在HTTP 1.1中则可以在一次连接中处理多个请求,并且多个请求可以重叠进行,不需要等待一个请求结束后再发送下一个请求。
 
由于HTTP在每次请求结束后都会主动释放连接,因此HTTP连接是一种“短连接”,要保持客户端程序的在线状态,需要不断地向服务器发起连接请求。通常的做法是即时不需要获得任何数据,客户端也保持每隔一段固定的时间向服务器发送一次“保持连接”的请求,服务器在收到该请求后对客户端进行回复,表明知道客户端“在线”。若服务器长时间无法收到客户端的请求,则认为客户端“下线”,若客户端长时间无法收到服务器的回复,则认为网络已经断开。

Guess you like

Origin www.cnblogs.com/Json159/p/11961291.html