Differences and connections between TCP/IP, IP, HTTP, and SOCKET

Source: Internet
Author: User

The differences between TCP, IP, HTTP, and SOCKET and the connection network are classified as follows: corresponding to the physical layer -- data link layer -- network layer -- IP protocol transmission layer -- TCP protocol Session Layer -- presentation layer and application layer -- HTTP protocol www.2cto.com socket is the encapsulation and Application of TCP/IP protocol (programmer level). It can also be said that the TPC/IP protocol is the transport layer protocol, mainly to solve how data is transmitted over the network, while HTTP is the application layer protocol, mainly to solve how to package data. The relationship between TCP/IP and HTTP is easy to understand:
"When transmitting data, we can only use the (Transport Layer) TCP/IP protocol. However, if there is no application layer, the data content cannot be identified, to make the transmitted data meaningful, you must use the application layer protocol. There are many application layer protocols, such as HTTP, FTP, and TELNET. You can also define the application layer protocol by yourself. The WEB uses HTTP as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network ."
What is the most commonly used socket? In fact, socket is the encapsulation of the TCP/IP protocol. The Socket itself is not a protocol, but a call interface (API) through Socket, we can use the TCP/IP protocol. In fact, the Socket and TCP/IP protocols are not necessarily related. The Socket programming interface is designed to adapt to other network protocols. Therefore, the appearance of Socket only makes it easier for programmers to use the TCP/IP protocol stack. It is an abstraction of the TCP/IP protocol, this forms some of the most basic function interfaces we know, such as create, listen, connect, accept, send, read, and write. The network has a saying that the relationship between socket and TCP/IP protocol is easier to understand:
"TCP/IP is just a protocol stack. Just like the operating mechanism of the operating system, it must be implemented in detail and provide external operation interfaces. Just as the operating system provides standard programming interfaces, such as win32 programming interfaces, TCP/IP also provides interfaces that programmers can use for network development. This is the Socket programming interface." Www.2cto.com summarizes some knowledge of TCP/IP-based applications and programming interfaces, that is, a lot of HTTP and Socket. CSDN has a more vivid description: HTTP is a car that provides a specific form of encapsulation or display data; Socket is an engine that provides network communication capabilities.
In fact, the TCP at the transport layer is based on the IP protocol at the network layer, while the HTTP protocol at the application layer is based on the TCP protocol at the transport layer, and the Socket itself is not a protocol, as mentioned above, it only provides an interface for TCP or UDP programming. The following are some important concepts that we often encounter during the written examination or interview. Here we will extract and summarize them.
I. What is the first handshake of three TCP connections: the client sends the syn Packet (syn = j) to the server and enters the SYN_SEND status, waiting for confirmation from the server; the second handshake: the server receives the syn packet, you must confirm the customer's SYN (ack = j + 1) and send a SYN Packet (syn = k), that is, the SYN + ACK packet. At this time, the server enters the SYN_RECV status; the third handshake: the client receives the server's SYN + ACK package and sends the ACK (ack = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the ESTABLISHED status, complete three handshakes.
The package transmitted during the handshake does not contain data. After the three-way handshake is completed, the client and the server formally start to transmit data. Ideally, once a TCP connection is established, the TCP connection will remain until either of the two parties closes the connection. When a TCP connection is disconnected, both the server and client can initiate a request to disconnect the TCP connection. The disconnection process must go through the "Four handshakes" (the process is not detailed, that is, the server interacts with the client, final confirmation of disconnection)
II. To establish a Socket connection by using a Socket, at least one Socket is required. One of them runs on the client, called ClientSocket, And the other runs on the server, called ServerSocket. The connection process between www.2cto.com sockets is divided into three steps: server listening, client requests, and connection confirmation. 1. Server listening: the server socket does not locate the specific client socket, but is waiting for connection. It monitors the network in real time and waits for client connection requests. 2. Client request: the client socket initiates a connection request, and the target is the server socket. Therefore, the client socket must first describe the socket of the server to be connected, point out the address and port number of the socket on the server, and then submit a connection request to the socket on the server. 3. Connection Confirmation: when the server socket monitors or receives a connection request from the client socket, it responds to the request from the client socket and creates a new thread, send the description of the server socket to the client. Once the client confirms the description, both parties establish a connection. The server socket continues to be in the listening status, and continues to receive connection requests from other client sockets.
3. HTTP links are characterized by Hypertext Transfer Protocol, which is the foundation of Web networking and one of the common protocols used for mobile phone networking, HTTP is an application built on TCP. The most notable characteristic of HTTP connection is that each request sent by the client requires a server to send a response. After the request ends, the connection is released. The process from establishing a connection to closing a connection is called "One connection ".
4. The difference between TCP and UDP is www.2cto.com 1. TCP is link-oriented. Although network instability and instability determine the number of handshakes, the connection reliability cannot be guaranteed, however, TCP's three-way handshake ensures the connection reliability to a minimum (which is actually guaranteed to a great extent), while UDP is not connection-oriented, UDP does not establish a connection with the other party before transmitting data, nor does it send a confirmation signal to the received data. The sending end does not know whether the data will be correctly received, and of course no re-transmission is required, therefore, UDP is a connectionless and unreliable data transmission protocol. 2. It is also because of the characteristics described in 1 that the UDP overhead is smaller and the data transmission rate is higher, because it does not need to confirm the sending and receiving data, so UDP has a better real-time performance. Knowing the difference between TCP and UDP makes it hard to understand why MSN using TCP transmission protocol is slower than QQ using UDP, but it cannot be said that QQ communication is insecure, because programmers can manually send and receive UDP data for verification, such as the sender serial number of each data packet and then the Receiver performs verification. Even so, due to the absence of TCP-like "three-way handshakes" in the encapsulation of the underlying protocol, UDP achieves the transmission efficiency that cannot be achieved by TCP. Author: talentluke

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.