Understanding socket, tcp, udp, http of

A, let's say a 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.

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,

Request includes a request method, URI, and the protocol version associated MIME message style.

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,

Therefore, a page that contains the HTML content and images will need to establish short-term TCP connections many times.

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.

3. Conclusion:

Although the HTTP protocol itself is a, but ultimately it 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.

HTTP、TCP、UDP、Socket   (C:\Users\Administrator\Desktop\socket2.jpg)

Second, the difference between TCP, UDP, HTTP, SOCKET

TCP and UDP: a transport layer protocol;

HTTP: application layer protocol;

SOCKET: API TCP / IP networks.

TCP / IP Representative Transmission Control Protocol / Internet Protocol, refers to a set protocol.

TCP and UDP IP protocol used to transfer data packets from one network to another. The thought of IP in Expressway, which allows other protocols running to the exit and find other computers on it.

TCP and UDP are "truck" on the highway, they carry cargo is like HTTP, FTP file transfer protocol such agreements.

TCP and UDP are transport layer protocols FTP, HTTP and SMTP like to use.

Although TCP and UDP are used to transport other protocols, they do have a significant difference: TCP provides guaranteed data transmission, UDP does not provide.

This means that TCP has a special mechanism to ensure data security without error transmitted from one endpoint to another endpoint, but UDP does not provide any such guarantee.

HTTP (hypertext transfer protocol) TCP protocol to transmit information between the two computers (typically a Web server and client) is utilized.

Clients use a Web browser sends an HTTP request to the Web server, Web server sends the requested information to the client.

Remember, you need IP protocol to connect to the network; TCP is a mechanism that allows us secure transmission of data, using the TCP protocol to transfer data to a special protocol is HTTP Web server and client use.

Socket Interface is a TCP / IP network API, Socket Interface defines a number of functions or routines to develop applications on a TCP / IP network.

Three, socket, tcp, udp, http understanding and difference

From bottom to top into the network physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer.
IP corresponds to the network layer protocol, TCP corresponds to the transport layer protocol, HTTP protocol corresponds to the application layer, the three are not comparable essence, socket is the TCP / IP protocol and encapsulation applications.
It can be said, TPC / IP protocol is the transport layer protocol, how to solve the main data transmission in the network, and HTTP is an application layer protocol, mainly to solve how to package data

socket is the encapsulation of TCP / IP protocol, Socket protocol itself is not, but a call interface (API),
through Socket, we can use the TCP / IP protocol.
In fact, Socket with TCP / IP protocol are not necessarily linked. Socket programming interface in the design, we hope to adapt other network protocols.
So, there is only the Socket makes it easier for programmers to use the TCP / IP protocol stack, it is an abstraction of the TCP / IP protocol,
thus forming a most basic function interface we know, such as create, listen, connect, accept, send, read and write, etc.

In fact, TCP transport layer protocol is based on the IP network layer, and HTTP application layer protocol is based on the TCP transport layer protocol,
and Socket protocol itself is not, as mentioned above, it only provides a for TCP or UDP programming interfaces

TCP three-way handshake connections:
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 packet, the customer must confirm the 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: a client server receives the SYN + ACK packet is transmitted to the server acknowledgment packet ACK (ack = k + 1) , this packet is sent, the client and server into the ESTABLISHED state, complete the three-way handshake.
Handshake package does not include the transfer of data, after three-way handshake is completed, the client and server before the official start transmitting data
while disconnected from the server and client sides can initiate a request to disconnect the TCP connection, disconnection process to go through. " handshake "

TCP is a link-oriented, although unsafe unstable characteristics of the network determines how many handshakes can not guarantee the reliability of the connection,
but the TCP three-way handshake at a minimum (actually large part to ensure a) to ensure that the the reliability of connection;
rather than UDP connection-oriented, before transferring data UDP does not establish a connection with each other, the received data is not the acknowledgment signal is transmitted,
the transmitting side does not know whether the data is correctly received, of course, not a retransmission, Therefore UDP is connectionless and unreliable data transmission protocol
so that a better real-time UDP also due to the above characteristics, so that higher costs are more small UDP data transfer rate, since no confirmation data transceiver, .

Therefore, using the TCP transport protocol file transfer slower than the QQ MSN using the UDP,
but it does not say QQ communication is insecure, because the programmer can manually verify the UDP data transmitting and receiving,
such as the sender for each data packet No. then verified by the recipient what ah,
even so, UDP protocol because the package does not use the underlying TCP-like "three-way handshake" is achieved TCP transmission efficiency can not be achieved.

Guess you like

Origin www.cnblogs.com/fan-gx/p/10962121.html