Interview path (4)-TCP/IP/HTTP Overview

Source: Internet
Author: User

Interview path (4)-TCP/IP/HTTP Overview
Basic TCP/IP knowledge

The full name of TCP/IP is Transmission Control Protocol/Internet Protocol. The IP address consists of 32 bits and 4 bytes. The IP address consists of the network ID and host ID. Class a ip Address: the first segment is the network ID, and the third segment is the host ID. The maximum number of network addresses must be zero. The network ID is 7 characters long and the host ID is 24 characters long. The number of hosts in A network can reach more than 1600. Type B IP Address: the first and second network IDs, and the third and fourth are the Host IDS. The maximum number of network addresses must be 10. The network ID is 14 bits and the host ID is 16 bits. Each network can accommodate up to 60 thousand hosts. Class c ip Address: the first three network IDs, and the rest are the Host IDS. The maximum number of network addresses must be 110. The network ID is 21 bits and the host ID is 8 bits. Each network can accommodate up to 254 hosts. The subnet mask is also a 32-bit IP address used to identify computers in the network. The IP addresses of the two hosts AND the subnet mask are used for the AND operation at the same time. If the result is the same, the two computers are in the same subnet AND can communicate directly. Domain Name composition: Host Name + organization name + network name + top-level domain name.
The Core protocols of the transport layer are TCP and UDP.

TCP provides one-to-one and connection-oriented reliable communication services. TCP establishes a connection, sorts and confirms sent packets, and restores lost packets during transmission. Unlike TCP, UDP provides one-to-one or one-to-many non-connection unreliable communication services.
In either TCP/IP or OSI reference model, any lower layer of the adjacent two layers serves as the service provider and the upper layer serves as the service caller. The services provided by the lower layer for the upper layer can be divided into two types: connection-oriented and connectionless services.

Connection-oriented network services

A connection-oriented network service, also known as a Virtual Circuit service, has three stages: network connection establishment, data transmission, and network connection release. It is a reliable packet grouping method for ordered transmission and is suitable for transmission of specified objects, long packets, and sessions.
The connection-oriented service is based on the telephone system. To talk to someone, first pick up the phone, dial the number, call, and then stop. When using a connection-oriented service, you must first establish a connection, use a connection, and then release the connection. Essentially, a connection is like a pipe: the sender puts an object at one end of the pipe, and the receiver extracts the object in the same order at the other end. The characteristic is that the data sent and received is not only in the same order, but also in the same content. -Call similar

Unconnected Network Services

You do not need to establish a connection before communication between two entities that have no connection to the network service. Connectionless network services can be classified into three types: Datagram, Confirmed Delivery, and Request reply ).
The unconnected service is in the postal system mode. Each packet (letter) carries a complete destination address, and each packet is independent of other packets and transmitted through the route selected by the system. Normally, when two packets are sent to the same destination, they are first served. However, it is also possible that the first packet is delayed on the way, and the sent packet is received first. This situation is absolutely impossible in connection-oriented services. -Text Messages

Transmission Control Protocol (TCP)

TCP stands for Transmission Control Protocol, which is named Transmission Control Protocol in Chinese. It can provide reliable and connection-oriented network data Transmission services. The transport control protocol mainly includes the following tasks and functions:

Tcp functions

Segment and reorganize the mass data sent by the program.
Ensure correct sorting and delivery of segmented data in order.
Check the integrity of transmitted data by calculating the checksum.
The message is sent based on whether the data is successfully received. By using selective confirmation, a negative confirmation is also sent to the unreceived data.
Provides the preferred transmission method to use reliable, session-based data transmission programs, such as client/server databases and email programs.

How TCP works

First, the sender host initiates a connection synchronization (SYN) request to the receiver host;
After receiving this request, the recipient's host replies a synchronous/confirmation (SYN/ACK) response to the sender's host;
After receiving the packet, the sender host sends an ACK message to the receiver host. The TCP connection is established successfully.
Once the initial three-way handshake is completed, the segments are sent and confirmed sequentially between the sending and receiving hosts. Before closing the connection, TCP uses a similar handshake process to verify whether both hosts have completed sending and receiving all data.
After three handshakes are completed, the client and the server start to transmit data.

About udp

The full name of UDP is User datav Protocol, and the Chinese name is User Datagram Protocol. UDP provides a connectionless network service that provides unreliable and best-effort transmission of data transmitted in messages. This means that it does not guarantee the arrival of the datagram, nor does it ensure that the order of the transmitted packets is correct.
I initially had a question: "Since UDP is an unreliable network protocol, what is the value or necessity ?"
In some cases, UDP may become very useful. Because UDP has a speed advantage beyond the reach of TCP. Although various security protection functions are embedded in TCP, a large amount of system overhead will be occupied during actual execution, and the speed will undoubtedly be seriously affected. In contrast, UDP eliminates the information reliable transfer mechanism and transfers security and sorting functions to upper-layer applications, greatly reducing the execution time and ensuring the speed.

TCP and port number

Both TCP and UDP are IP-level transmission protocols and are the processing interfaces between the IP address and the upper layer. TCP and UDP port numbers are designed to distinguish the IP addresses of multiple applications running on a single device. Because multiple network applications may run on the same computer, the computer must ensure that the software applications on the target computer that receive data packets from the source host are correct, and the response can be sent to the correct application on the source host. This process is implemented by using the TCP or UDP port number.
-- Each application registers a port number on the NIC to distinguish the communication between applications on the same device.

In the TCP and UDP headers, there are "Source Port" and "Target Port" segments, which are mainly used to display identity identification information during sending and receiving. The combination of IP addresses and port numbers is called "socket ". TCP ports are complex and work in different ways than UDP ports. The UDP port operates UDP-based communication as a single message queue and network endpoint, and the end point of all TCP communication is a unique connection. Each TCP connection is uniquely identified by two endpoints. Because all TCP connections are uniquely identified by two pairs of IP addresses and TCP ports (each connected host has an address/Port Pair ), therefore, each TCP server port can provide shared access to multiple connections.

HTTP protocol

HyperText Transfer Protocol (HTTP) is the most widely used network Protocol on the Internet.
The http Protocol specifies the data transmission format between the client and the server.

Http advantages:

Simple and fast:
The http protocol is simple and the communication speed is fast;
Flexibility:
The http protocol allows transmission of any type of data;
Transient connection:
The http protocol limits that only one request can be processed for each connection. After the server responds to the client request, the connection is immediately disconnected. This method can save transmission time.

Http request: the client requests data from the server.
Http protocol: a complete http request contains three parts: 'request line', 'request head', and 'request body'. Request Line: contains the request method, request resource path, http Protocol version. "GET/resources/images/HTTP/1.1" Request Header: contains the Environment Description of the client, the host address requested by the client, and other information. accept: text/html (the data type that the client can receive) Accept-Language: zh-cn (the Language environment of the client) Accept-Encoding: gzip (the data compression format supported by the client) host: m.baidu.com (address of the server Host to be accessed by the client) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X10.10 rv: 37.0) gecko/20100101 Firefox/37.0 (client type, client software environment) Request body: the specific data sent from the client to the server, such as files/images.
Response: The server returns the desired data from the client.
Http protocol requirements: A complete http response contains three parts: 'status line', 'response head', and 'entity content'. Status line: contains the http protocol version, status, english name of the status. "HTTP/1.1 200 OK" Response Header: contains the description of the server and the returned data. content-Encoding: gzip (the data compression format supported by the server) Content-Length: 1528 (the Length of the returned data) Content-Type: application/xhtml + xml; charset = UTF-8 (returned data type) Date: Mon, 15Jun201509: 06: 46GMT (Response Time) Server: apache (Server type) entity content: the specific data (image/html/file...) that the server returns to the client ...).
Http Method

Http defines many methods that correspond to different resource operations. The most common methods are GET and POST.
Eg: GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, CONNECT, PATCH
Add: PUT
DELETE: DELETE
Change: POST
Query: GET
Because GET and POST can implement all the preceding operations, in actual development, the GET and POST methods are the most widely used. In addition, HEAD requests are frequently used;

GET
After the request URL? Parameters are concatenated in the form of "parameter name" = "parameter value". Multiple parameters are separated;
The essence of GET is to GET data from the server, which is more efficient. And GET requests can be cached.
Note: The length of GET is limited. Different browsers have different length limits, generally between 2 ~ Between 8 K;
POST
The essence of POST is to send data to the server and obtain the results processed by the server. The efficiency is not as high as that of GET. POST requests cannot be cached. After each refresh, the form must be submitted again.
All parameters sent to the server are placed in the 'request body;
Theoretically, there is no limit on the amount of data transmitted by POST.
Note: All data involving user privacy (password/bank card number, etc ...) It must be passed in POST mode.
HEAD
The HEAD method is usually used to obtain the file information of the remote server before downloading the file! Compared with GET requests, object data is not downloaded and only response header information is obtained!
Generally, the HEAD method is used to inform users of the object to be downloaded in advance. The user determines whether to download the object! Therefore, the HEAD method is recommended to send a synchronization request!

Response Message

1xx: Information Response class, indicating that the request is received and processed continuously
2xx: Successful response class, indicating that the action is successfully received, understood, and accepted
3xx: redirect response class. To complete the specified action, you must accept further processing.
4xx: client error. The client request contains a syntax error or cannot be correctly executed.
5xx: A server error occurs. The server cannot correctly execute a correct request;

Status Code
1xx: Information Message description 100 The Continue server only receives some requests, but once the server does not reject the request, the client should Continue to send other requests. 101 Switching Protocols server conversion protocol: the server converts client requests to another protocol. 2xx: Success Message description 200 OK request succeeded (followed by the response document for GET and POST requests .) 201 The Created request is Created and a new resource is Created. 202 The Request for Accepted processing has been Accepted but not completed. 203 the Non-authoritative Information document has been normally returned, but some response headers may be incorrect because the document is copied. 204 No Content there is No new document. The browser should continue to display the original document. This status code is useful if the user regularly refreshes the page and the Servlet can determine that the user document is new enough. 205 there is no new document in Reset Content. But the browser should reset the content it shows. Used to force the browser to clear the input content of the form. 206 Partial Content the client sent a GET request with a Range header and the server completed it. 3xx: Redirect Message description 300 Multiple Choices Multiple options. Link List. You can select a link to reach your destination. Up to five addresses are allowed. 301 the page requested by Moved Permanently has been transferred to the new url. 302 the page requested by Found has been temporarily transferred to the new url. 303 the page requested by See Other can be found in another url. 304 Not Modified did Not modify the document as expected. The client has a buffered document and sends a conditional request (generally, the If-Modified-Since header is provided to indicate that the customer only wants to update the document on a specified date ). The server tells the customer that the original buffer documentation can still be used. 305 the document requested by the Use Proxy client should be extracted from the Proxy server specified by the Location header. 306 Unused this code is used in the previous version. It is no longer used, but the code is still retained. 307 the requested page of Temporary Redirect has been temporarily moved to the new url. 4xx: client Error Message description 400 Bad Request server does not understand the Request. 401 the user name and password are required for the page requested by Unauthorized. 401.1 Logon Failed. 401.2 logon fails due to server configuration. 401.3 the ACL is not authorized due to resource restrictions. 401.4 filter authorization failed. 401.5 authorization for ISAPI/CGI applications fails. 401.7 access is denied by URL Authorization policies on the Web server. This error code is dedicated to IIS 6.0. 402 Payment Required this code is not available yet. 403 Forbidden access to the requested page is Forbidden. 403.1 access is forbidden. 403.2 read access is forbidden. 403.3 write access is forbidden. 403.4 require SSL. 403.5 requires SSL 128. The 403.6IP address is rejected. 403.7 client certificates are required. 403.8 site access is rejected. Over 403.9 users. 403.10 the configuration is invalid. 403.11 change the password. 403.12 access to the ing table is denied. 403.13 the client certificate is revoked. 403.14 reject the directory list. 403.15 the client access permission is exceeded. 403.16 the client certificate is untrusted or invalid. 403.17 the client certificate has expired or has not yet taken effect. 403.18 the requested URL cannot be executed in the current application pool. This error code is dedicated to IIS 6.0. 403.19 CGI cannot be executed for clients in this application pool. This error code is dedicated to IIS 6.0. 403.20 Passport Logon Failed. This error code is dedicated to IIS 6.0. 404 The Not Found server cannot find the requested page. 404.0 (none)-No file or directory found. 404.1 the website cannot be accessed on the requested port. The 404.2Web service extended locking policy blocks this request. 404.3 the MIME ing policy blocks this request. 405 the Method specified in the Method Not Allowed request is Not Allowed. 406 the response generated by the Not Acceptable server cannot be accepted by the client. 407 Proxy Authentication the Required user must first use the Proxy server for Authentication so that the request will be processed. 408 The Request Timeout exceeds the waiting time of the server. 409 Conflict requests cannot be completed due to a Conflict. 410 the requested page of Gone is unavailable. 411 Length Required "Content-Length" is not defined. If no such content exists, the server will not accept the request. 412 the Precondition in the Precondition Failed request is evaluated as Failed by the server. 413 Request Entity Too Large because the requested Entity is Too Large, the server will not accept the Request. 414 Request-url Too Long because the url is Too Long, the server will not accept the Request. This happens when a post request is converted to a get request with a long query information. 415 Unsupported Media Type the server does not accept the request because the Media Type is not supported. 416 the Requested Range Not Satisfiable server cannot meet the Range header specified by the customer in the request. 417 Expectation Failed execution Failed. 423 locking error. 5xx: Server Error Message description 500 the Internal Server Error request has not been completed. Unpredictable server conditions. 500.12 the application is busy restarting on the Web server. The Web server is too busy. 500.15 direct request to Global. asa is not allowed. Invalid 500.16UNC authorization credential. This error code is dedicated to IIS 6.0. The authorized storage of 500.18URL cannot be opened. This error code is dedicated to IIS 6.0. 500.100 internal ASP error. 501 Not Implemented request Not completed. The server does not support the requested functions. 502 Bad Gateway request not completed. The server receives an invalid response from the upstream server. The 502.1CGI application times out. · 502. 2CGI application error. 503 Service Unavailable request not completed. Temporary server overload or Server Load balancer. 504 Gateway Timeout Gateway times out. 505 the HTTP Version Not Supported server does Not support the HTTP protocol Version specified in the request.

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.