The difference and connection of Tcp/ip,http,socket

Source: Internet
Author: User

A remembrance of the past, full of remorse tears.

? ? ? Learned in school, the network seven layer, also know the TCP three handshake. But because it is useless in the actual development, so gradually forgotten. Now understand the next three differences and connections. Two business

? ? ? Network layer Seven: The number of Objects webcast table should be. The physical layer, the data link layer, the network layer, the Transport layer, the session layer, the presentation layer, the application layer. Among them, the bottom three layer: the physical layer, the data link layer, the network layer is the network Engineer research object, and the other four layers, is the user orientation and

HTTP protocol: Hypertext Transfer Protocol, corresponding to the application layer.

TCP protocol: Transmission Control Protocol, corresponding to the transport layer.

IP protocol: Corresponds to the network layer.

? ? ? ? TCP/IP is the Transport layer protocol, which mainly solves the transmission of data in the network. HTTP is an application-layer protocol that is used to encapsulate data. When transferring data, only the TCP/IP protocol (Transport layer) is used. If there is no application layer to identify the data content, the transmitted protocol is useless.
There are many application layer protocols, such as Ftp,http,telnet, which can define the application layer protocol. The web uses HTTP as the Transport Layer protocol. To encapsulate HTTP text information, and then use TCP/IP as the Transport layer protocol to send data to the network.

? ? ? ? socket is the TCP/IP protocol encapsulation, socket is just an interface, not protocol , through the socket, we can use the TCP/IP protocol.
Of course, in addition to TCP, you can also use the UDP protocol to pass data.

Three HTTP and socket connection differences


1 TCP connections
To understand the socket, you must understand the TCP connection.
? ? ? ? To establish a "three-time handshake" for a TCP connection:
? ? ? ? First time: The client sends a SYN packet (SYN=J) to the server and is in the Syn_send state at the same time.
? ? ? ? Second time: After the server receives the SYN packet, it must confirm the customer's SYN (SYN=J+1), and also send a SYN packet (SYN=K), which is the Syn+ack packet, when the server enters the SYN_RECV state.
? ? ? ? Third: When the client receives the Syn+ack packet from the server, it sends a SYN (SYN=K+1) to the server, and the server and the client enter the established state after it is sent. Complete the three-time handshake.
During a handshake, the data is not transmitted. After the handshake, the server and the client start transmitting data, ideally, once the TCP connection is established, the TCP connection will persist until either side of the communication is actively disconnected.
2 HTTP Connection
? ? ? ? The most significant feature of http: The client sends a request that requires a server-side loopback response. After the request is over, release the link voluntarily. HTTP is a short connection. The usual practice is that you don't need any data, and you want to keep a "keep-alive" request to the server at regular intervals. This ensures that the client is "on-line" on the server side.

3 Socket principle
? ? ? ? The socket connection requires at least a pair of sockets, divided into clientsocket,serversocket. The connection is divided into 3 steps:
Server monitoring: The server does not locate the specific client socket, but is always in the listening state.
Client request: The socket of the client to describe the socket of the server it is connecting to. Provide the address and port number, and then make a connection request to the server socket.
Connection confirmation: When the server socket receives a request from the client socket, it responds to the client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the connection is formally established. And the server socket continues to be in the listening State, Continue to receive connection requests from other client sockets.
4 socket connection to TCP connection
When you create a socket connection, you can specify the transport layer protocol. It can be TCP or UDP, and the socket is a TCP connection when it is connected by TCP.
5 Socket connection and HTTP connection
Usually, the socket connection is a TCP connection, so once the socket connection is established, both sides of the communication begin to send data to each other until the two sides are disconnected. In practice, due to excessive network nodes, the nodes are disconnected during transmission. So by polling the high-speed network, The node is in an active state.
The HTTP connection uses a "request-response" approach, not only to establish a connection on the request, but also to return the data to the server after the client requests it.

? ? ? In many cases, it is necessary for the server to actively push the data to the client and keep the client and the server in real-time synchronization. If the two sides are socket connections, data can be sent directly to the client. If both are HTTP connections, the server needs to wait for the client to send the request. To pass data back to the client. Therefore, the client periodically sends a request to the server, not only to remain online, but also to ask the server if it has new data, and if so, pass the data to the client.

The difference and connection of Tcp/ip,http,socket

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.