Network protocol HTTP, TCP/IP, Socket

Source: Internet
Author: User
Tags network function

Network protocol HTTP, TCP/IP, Socket

The network seven layer is from the bottom up to the physical layer, the data link layer, the network layer, the transport layer, the conversation layer, the presentation layer and the application layer respectively.
The physical layer, the data link layer and the network layer are often called media layers, which are the objects researched by network engineers.
The transport layer, the session layer, the presentation layer, and the application layer are referred to as the host layer and are the content that the user is looking for and cares about.
The HTTP protocol corresponds to the application layer to primarily address how the data is packaged
The TCP protocol corresponds to the transport layer that primarily addresses how data is transmitted over the network

The IP protocol corresponds to the network layer, which mainly solves how the data is transmitted over the network.

We use the Transport layer (TCP/IP) when transmitting data, but if we do not encapsulate the data with the Application Layer protocol HTTP protocol, we cannot recognize the data content, there are many application layer protocols, such as HTTP, FTP, Telnet, etc., and you can define the application layer protocol yourself.  The web uses HTTP as the Transport Layer protocol to encapsulate HTTP text information and then send it to the network using TCP/IP as the Transport layer protocol. Socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol.

The difference between get and post:
Get can only transfer 128K of data and get the URL of the submission no more than 256 bytes post is unlimited

The query content that is submitted by the Get method is displayed in the browser address bar when post submission is not displayed on the browser
Get method is applied to query information, according to the HTTP protocol,
Generally more important data through the post, because get is someone else can change the parameter value of other people to write parameters, your abnormal report not stop

HTTP and socket (TCP/IP) connection differences

TCP connections

To understand the socket connection, you need to understand the TCP connection first. Mobile phone can use the network function is because the bottom of the mobile phone implementation of TCP/IP protocol, you can make the mobile phone terminal through the wireless network to establish a TCP connection. TCP protocol can provide an interface to the upper network, so that the transmission of the upper network data is based on the "No Difference" network.
Establishing a TCP connection requires a "three handshake", the so-called three-time handshake (three-way handshake), which means that the client and server are required to send a total of 3 packets when establishing a TCP connection. The purpose of the three-time handshake is to connect the server to the specified port, establish a TCP connection, and synchronize the serial number and confirmation number of both parties and Exchange TCP window size information. In socket programming, the client executes connect () and triggers three handshakes.
First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
Second handshake: The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;
Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times.
specifically put

After a TCP connection is established, the client and the server can communicate with each other, and when a TCP connection is required, both the server and the client can initiate a request to disconnect the TCP connection

Disconnecting a TCP connection requires a "four-time handshake"


SOCKET
Socket (socket) is the cornerstone of communication and is the basic operating unit of network communication supporting TCP/IP protocol. It is an abstract representation of the endpoint in the network communication process and contains five kinds of information that must be used for network communication: the protocol that the connection uses, the IP address of the local host, the protocol port of the local process, the IP address of the remote host, and the protocol port of the remote process.
When the application layer communicates data through the transport layer, TCP encounters a problem that provides concurrent services for multiple application processes at the same time. Multiple TCP connections or multiple application processes may require data to be transmitted over the same TCP protocol port. To differentiate between different application processes and connections, many computer operating systems provide a socket (socket) interface for applications interacting with the TCP/IP protocol. The application layer can communicate with the transport layer through the socket interface, differentiate the communication from different application processes or network connections, and realize the concurrent service of data transmission.

Establishing a socket connection
Establishing a socket connection requires at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket.
The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.
Server monitoring: Server-side sockets do not locate specific client sockets, but are waiting for the status of the connection, real-time monitoring network status, waiting for the client connection request.
Client request: Refers to the client's socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.
Connection confirmation: When a server-side socket hears or receives a connection request from a client socket, it responds to a 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 two sides formally establish the connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.

HTTP connection

The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol. The HTTP connection uses a "request-response" approach that supports client/server mode, not only when a connection is made at the time of the request, but when the client makes a request to the server before the server can respond to the data. HTTP is a non-connected, most notable feature is that each request sent by the client requires a server loopback response, and after the request ends, the connection is actively released. The process from establishing a connection to closing a connection is called a "one-time connection."

After a client establishes a connection to the server, it sends a request to the server in the form of a Uniform Resource Identifier, protocol version number, followed by MIME information including the request modifier, client information, and possible content. After the server receives the request, it gives the corresponding response information in the form of a status line that includes the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content.

In HTTP1.0, each request from the client requires a separate connection to be established, and the connection is automatically freed after the request is processed. That is, "short connection".

In HTTP1.1, multiple requests can be processed in a single connection, and multiple requests can overlap, without waiting for a request to end before sending the next request. No data is needed immediately, and the client also keeps sending a "keep-connected" request to the server at regular intervals, and the server responds to the client after receiving the request, indicating that the client is "online". If the server can not receive the client's request for a long time, it is considered that the client "offline", if the client can not receive a reply from the server for a long time, the network has been disconnected, release the connection.

Network protocol HTTP, TCP/IP, 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.