Interview Road (4)-tcp/ip/http overview

Source: Internet
Author: User
Tags ack message queue top level domain

Basic knowledge of TCP/IP
The TCP/IP full name is transmission Control protocol/internet Protocol. IP Address Total +-bit4Bytes. The IP address is divided into two parts: the network identity and the host identity.AClass IP Address: The first segment is the network identity, and the remaining three segments are the host identity. The highest bit of network address must be zero. The network ID length is7Bit, the host ID length is --bitAThe number of hosts in a class network can be up to theMultiple units. Class B IP Address: The first to second segment of the network identity, the third to fourth is the host identity. The highest bit of network address must beTen。 The network ID length is -bit, host identity length bit --bit Each network can accommodate up to6Multi-machine host. Class C IP Address: The first three segment network identification, the remaining part of the host identity. The highest bit of network address must be the。 The network ID length is +Bit, the host ID length is8-bit Each network accommodates up to254Console host. The subnet mask is also +IP address of a bit, which is used to identify computers within the network. The IP addresses of two different hosts are simultaneously associated with the subnet mask andoperation, if the result is the same, the two computers are in the same subnet and can communicate directly. The composition of the domain name: Host name + organization name + Network name + top level domain name.
The core protocol of the Transport layer is TCP and UDP.

TCP provides a one-to-one, connection-oriented, reliable communication service. TCP establishes a connection, sorts and confirms the packets sent, and recovers packets that were lost during transmission. Unlike TCP, UDP provides one-to-one or one-to-many, non-connected, unreliable communication services.
Either TCP/IP or the OSI reference Model, the lower layer of any adjacent two tiers is the service provider, and the upper layer is the service caller. The services provided on the lower level are divided into two categories: connection-oriented and no-connection services.

Connection-oriented network services

The connection-oriented network service, also known as virtual circuit (virtual circuit) service, has three stages of network connection establishment, data transmission and network connection release. is the sequential transmission of reliable packet grouping, suitable for the specified object, long message, session-type transmission requirements.
The connection-oriented service is modal to the telephony system. To talk to someone, first pick up the phone, dial the number, call, and then hang up. Also when using a connection-oriented service, the user first establishes a connection, uses the connection, and then releases the connection. A connection is essentially a pipe: the sender puts an object at one end of the pipe, and the receiver takes the object in the same order at the other end, with the characteristic that the data sent and received are not only consistent in order but also of the same content. – Similar calls

No Connected network services

Communication between two entities without a connection to the Network service does not require a good one connection to be established beforehand. There are 3 types of non-connected network services: Datagram (Datagram), acknowledgment of delivery (confirmed Delivery) and request for answer (requests reply).
No connection service is in the postal system mode. Each message (letter) has a complete destination address, and each message is independent of other messages and is routed by the system-selected route. Under normal circumstances, when two messages are sent to the same destination, first comes first. However, it is also possible that the first message is delayed on the way, but the message is received first, which is absolutely not possible in a connection-oriented service. – Similar texting

Transmission Control Protocol (TCP)

TCP full name is transmission Control Protocol, the Chinese name is the transmission protocol, it can provide a reliable, connection-oriented network data delivery service. The Transmission Control protocol primarily includes the following tasks and features:

TCP Features

Fragment and reorganize large chunks of data sent by the program.
Ensure that segmented data is correctly sorted and delivered sequentially.
The integrity of the transmitted data is checked by calculating the checksum.
The positive message is sent based on whether the data was received successfully. By using selective acknowledgments, negative acknowledgments are also sent for data that is not received.
Provides the preferred transfer method for the use of reliable, session-based data transfer programs, such as client/server databases and e-mail programs.

How TCP Works

First, the sending host initiates a synchronous (SYN) request to the receiving host to establish a connection;
The receiving host responds to a synchronization/acknowledgment (Syn/ack) response to the sending host after receiving the request;
When the sender host receives this package and then sends an acknowledgment (ACK) to the receiving host, the TCP connection is successfully established.
Once the initial three-time handshake is complete, 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 that two hosts have completed sending and receiving all of the data.
Three handshake is completed and the client and server begin to transfer data.

UDP introduction

The UDP full name is User Datagram Protocol, the Chinese name is the Subscriber datagram protocol. UDP provides a non-connected network service that provides unreliable, maximum-effort transmission of data that is transmitted in the message. This means that it does not guarantee the arrival of the datagram, nor does it guarantee the correct order of the packets being transmitted.
I initially had a question: "Since UDP is an unreliable network protocol, what use or necessity is there?" ”
In some cases, UDP may become very useful. Because UDP has the speed advantage that TCP can not catch. Although a variety of security features are embedded in TCP, there is a significant amount of overhead involved in the actual execution of the system, which undoubtedly makes the speed seriously affected. In view of the elimination of the information reliable transmission mechanism, the security and sequencing functions are transferred to the upper application to complete, which greatly reduces the execution time and makes the speed guaranteed.

TCP and Port numbers

Both TCP and UDP are IP-level transport protocols, which are the processing interfaces between IP and the upper layer. The TCP and UDP port numbers are designed to differentiate the IP addresses of multiple applications running on a single device. Because more than one network application may run on the same computer, the computer needs to ensure that the software application that receives the source host packet on the target computer is correct and that the response can be sent to the proper application on the source host. This process is accomplished by using TCP or UDP port numbers.
-that is, each application registers a port number on the NIC to differentiate between applications on the same device

In the TCP and UDP header sections, there are "source port" and "Destination port" segments that are used primarily to display identification information during the sending and receiving process. The combination of IP address and port number is called "socket". TCP ports are more complex and work differently than UDP ports. UDP ports operate on UDP-based communication as a single message queue and as a network endpoint, and all TCP traffic endpoints are unique connections. Each TCP connection is uniquely identified by a two endpoint. Because all TCP connections are uniquely identified by two IP addresses and TCP ports (each host has an address/port pair), each TCP server port can provide shared access to multiple connections

HTTP protocol

Hypertext Transfer Protocol (Http,hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet.
The HTTP protocol specifies the format of data transfer between the client and the server.

HTTP Advantages:

Simple and quick:
HTTP protocol is simple, communication speed is fast;
Flexible:
The HTTP protocol allows the transmission of arbitrary types of data;
Short connections:
The HTTP protocol restricts each connection to only one request, and the server immediately disconnects after responding to a request from the client. This method can save transmission time.

Use Process request for HTTP protocol: client requests data from server.
The HTTP protocol stipulates that a complete HTTP request contains' request line ',' request header ',' request body 'three parts; Request line: Contains the request method, the request resource path, the HTTP protocol version. "get/resources/images/http/1.1"Request Header: Contains information about the client's environment description, the host address requested by the client, etc..accept:text/html (data types that the client can receive) accept-language: En-CN(Client's locale) Accept-encoding: gzip (data compression format supported by the client) host:m.Baidu.COM (the server host address the client wants to access) User-agent: mozilla/5.0(Macintosh;intel Mac OS X10. TenRv:37.0) gecko/20100101firefox/37.0(Client-type, client-side software Environment) request body: Specific data that the client sends to the server, such as a file/Pictures, etc..
Response: The server returns the data the client wants
http协议规定:一个完整的http响应包含‘状态行‘,‘响应头‘,‘实体内容‘三个部分;状态行:包含了http协议版本,状态吗,状态英文名称."HTTP/1.1 200 OK"1528(返回数据的长度)Content-Type:application/xhtml+xml;charset=utf-8(返回数据的类型)Date: Mon,15Jun201509:06:46GMT(响应的时间) Server: apache (服务器类型)实体内容:服务器返回给客户端的具体数据(图片/html/文件...).
HTTP method

The HTTP protocol defines a number of methods that correspond to different resource operations, the most common of which are the get and post methods.
Eg:get, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, CONNECT, PATCH
Add: PUT
Delete: Delete
Change: POST
Check: GET
Because get and post can do all of the above, so in real-world development, get and post methods are the most widely used, in addition to the head request usage frequency is also relatively high;

GET
After the request URL in the form of a to follow the parameters issued to the server, the parameters are "parameter name" = "parameter value" in the form of splicing, multiple parameters are separated by &;
The essence of get is that it is more efficient to get data from the server. And a GET request can be cached.
Note: The length of get is limited, and different browsers have different length limits, generally between 2~8k;
POST
The essence of post is to send data to the server, but also to get the result after the server processing, the efficiency is not as Get.post request can not be cached, after each refresh will need to resubmit the form.
The parameters sent to the server are all placed in the ' request body ';
In theory, there is no limit to the amount of data that post transmits.
Note: All data related to user's privacy (password/bank card number etc...) Must be delivered by post.
HEAD
The head method is usually used to get the file information of the remote server before downloading the file! File data is not downloaded and only the response header information is obtained, compared to a GET request!
In general, the purpose of using the head method is to tell the user in advance to download the file information, the user determines whether to download the file! So, head method, it is best to send a sync request!

Response message

1XX: Information response class, which indicates receipt of request and continues processing
2XX: Handle the successful response class, indicating that the action was successfully received, understood, and accepted
3XX: Redirect Response class, must accept further processing in order to complete the specified action
4XX: Client error, client request contains syntax error or is not executed correctly
5XX: Server error, the servers do not correctly execute a correct request;

Status code
1XX: Information message description - ContinueThe server only receives partial requests, but once the server does not reject the request, the client should continue to send the remaining requests.101Switching protocols Server Conversion protocol: The server translates the client's request to another protocol.2XX: Success Message description $The OK request succeeds (followed by the answer document for the Get and post requests.) )201The created request is created and the new resource is created.202accepted the request for processing was accepted, but processing was not completed.203Non-authoritativeInformationThe document has returned normally, but some of the answer headers may be incorrect because a copy of the document is being used.204No content does not have a new document. The browser should continue to display the original document. This status code is useful if the user refreshes the page on a regular basis and the servlet can determine that the user's document is new enough.205Reset content does not have a new document. But the browser should reset what it displays. Used to force the browser to clear the form input.206The Partial content client sends aRangeA GET request for the header, the server finishes it.3XX: Redirect Message description -Multiple choices multiple options. A list of links. The user can select a link to reach the destination. A maximum of five addresses are allowed.301Moved permanently The requested page has been transferred to the new URL.10pFound the requested page has been temporarily transferred to the new URL.303The page requested by see other can be found under a different URL.304  notModified the document was not modified as expected. The client has a buffered document and issues a conditional request (typically aIfThe-modified-since header indicates that the customer only wants documents that are newer than the specified date. The server tells the customer that the original buffered document can continue to be used.305The document requested by the use proxy client should be extracted from the proxy server indicated by the location header.306Unused this code is used in the previous version. It is no longer used, but the code is still retained.307 TemporaryRedirect The requested page has been temporarily moved to the new URL.4XX: Client Error message description -Bad Request server failed to understand requests.401Unauthorized the requested page requires a user name and password.401.1Login failed.401.2The server configuration caused the login to fail.401.3The ACL has not been authorized because of the resource limitation.401.4Filter authorization failed.401.5ISAPI/CGI application authorization failed.401.7Access is accessed by the WEB server on theURLAuthorization policy denied. This error code is IIS6.0is dedicated.402Payment required This code is not yet available.403Forbidden access to the requested page is forbidden.403.1Execution access is forbidden.403.2Read access is forbidden.403.3Write access is forbidden.403.4Requires SSL.403.5Require SSL -。403.6The IP address is rejected.403.7Requires a client certificate.403.8Site access is denied.403.9Excessive number of users.403.10The configuration is not valid.403.11Password changes.403.12Access to the mapping table is denied.403.13The client certificate was revoked.403.14Reject directory list.403.15Client access permission exceeded.403.16The client certificate is not trusted or invalid.403.17The client certificate has expired or is not yet valid.403.18The requested request cannot be performed in the current application pool.URL。 This error code is IIS6.0is dedicated.403.19You cannot execute CGI for clients in this application pool. This error code is IIS6.0is dedicated.403.20Passport Login failed. This error code is IIS6.0is dedicated.404  notThe found server was unable to find the requested page.404.0(none) – No files or directories found.404.1The Web site cannot be accessed on the requested port.404.2The WEB service extended lockdown policy blocks this request.404.3The MIME mapping policy blocks this request.405 Method  notThe method specified in the allowed request is not allowed.406  notThe response generated by the acceptable server cannot be accepted by the client.407Proxy Authentication required the user must first authenticate with a proxy server so that the request is processed.408Request timeout requests exceeded the server's wait time.409Conflict the request could not be completed due to a conflict.410Gone the requested page is not available.411 LengthRequired"Content-length"is not defined. If there is no such content, the server will not accept the request.412The prerequisites in the precondition failed request are evaluated by the server as failed.413Request Entity TooLargeThe server does not accept the request because the requested entity is too large.414Request-url Too long because the URL is too long, the server will not accept the request. This occurs when the POST request is converted to a GET request with very long query information.415Unsupported media Type the server does not accept requests because the media types are not supported.416RequestedRange  notThe satisfiable server does not meet the customer specified in the requestRangeHead.417 expectationFailed execution failed.423The locked error.5XX: Server error message description -Internal Server Error request was not completed. The server encountered unpredictable conditions.500.12The application is busy restarting on the WEB server.500.13The WEB server is too busy.500.15Direct request Global.asa is not allowed.500.16The UNC authorization credentials are incorrect. This error code is IIS6.0is dedicated.500.18URLThe authorization store cannot be opened. This error code is IIS6.0is dedicated.500.100Internal ASP error.501  notThe implemented request was not completed. The requested functionality is not supported by the server.502Bad gateway request not completed. The server received an invalid response from the upstream server.502.1The CGI application timed out.502.2Error in CGI application.503The Service unavailable request was not completed. The server is temporarily overloaded or in a machine.504The gateway timeout is timed out.505HTTPVersion  notThe supported server does not support the HTTP protocol version indicated in the request.
Reference links

Http://www.ruanyifeng.com/notes/2007/02/tcpip.html
http://www.jianshu.com/p/cc756016243b

Interview Road (4)-tcp/ip/http overview

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.