Summed up their computer networks common interview questions

Their notes, their only see to understand, I did not say a lot of pictures, forgive me

TCP / IP reference model

Here Insert Picture Description

Talk about the TCP three-way handshake

IP protocol is a connectionless protocol, he does not occupy a communication line two communicating computers, thus reduces the need for IP network line, each line can be communication needs between different computers at the same time. By IP message is divided into smaller more independent package and send it before the computer via the Internet, IP is responsible for routing each packet to his destination. IP protocol does not do anything to confirm that the data packets sequentially transmitted, or whether the packet is damaged, the IP packet is not reliable. He needs to be made is controlled by the upper layer protocols.

TCP is connection-oriented, reliable transport layer protocol based on the byte stream. TCP application layer data stream into segments, TPCP order not to lose packets, each packet has a sequence number, i.e., Sequence Number, but also to ensure that the number is transferred to the sequential processing of the packet destination node, and the receiver entity already received a corresponding packet transmission acknowledgment, ACK acknowledgment i.e., if the transmitting side entity within a reasonable round-trip time RTT i.e. not received within the acknowledgment, the corresponding data packet will be assumed to have been lost, and will to is retransmission. TCP and parity with a function to check whether the data has an error, to be calculated at the time of sending and receiving a checksum.

So TCP three-way handshake to establish a connection is a full duplex channel between two computers, it will take up a line of communication between the two computers. Until he was one or both closed.Here Insert Picture Description
Here Insert Picture Description

Why do we need three-way handshake to establish a connection it up?

What do you answer those online answer is I say to outsiders hear! !
Mainly to initialize the initial value of the Sequence Number, the communicating parties to inform each other of their own initialization Sequence Number, which is the figure above and X Y, the number subsequent to the number of a data communication to ensure that the application layer receives the data will not be transmission problems on the network and out of order, that is, TCP will use this number to splice data, so the server sent back to his sequence number that is, after the second handshake, the client needs to send confirmation message to the server , tells the server that the client has received your Sequence Number, and moreover when the first handshake, there is a risk that the issue SYN timeout, the server receives a client's SYN, SYN-ACK reply when the client dropped a server ACK is not received confirmation, then the link will be in an intermediate state, that is, without success nor failure, so the server does not receive acknowledgment clients within a certain time, it will resend SYN (Sing) -ACK, in Linux, the default retry 5 times for one second from the start retry doubled (total work chamber 63 sec). This might cause the server SYN-Flood attack risk of malicious programs it would give the server sends a SYN packet, after he made it off the assembly line, so the server will default to 63 seconds and so on, will not open this link so attackers will connect to this server SYN queue it up, leave your normal connection request can not be processed, so it under Linux, there is a tcp_syncookies to deal with this matter, when the SYN queue is full, TCP will build the port by the source address destination address port, and a time stamp special Sequence (SYN Cookie) back hair back if it is attacked, he will not have a response, if it is properly connected, and this will be a Cookie sent back, the server can then establish a connection through a Cookie, by SYN Cookie SYN queue even if we are full. The connection request is not in the queue, is still able to establish a connection, so to solve this problem.

If a connection is established, the client still has failed how to do?

TCP has a keep-alive mechanism, within the keep-alive time, the connection is inactive, the server to the client to send keepalive messages, not receive a response continues to send until the number of attempts to achieve security detection will break the connection alive .

TCP's four wave

Wave to terminate the connection. In Socket programming, there is a client or server to perform close to the trigger. Here Insert Picture Description
Here Insert Picture Description
1. Why Finally, the client also has a Time Wait state, in order to ensure there is enough time to the other received the ACK packet, if the party does not receive a passive close ACK packet, then the party will be closed passive FIN packet retransmission, the one a visit is just two MSL.

2. have enough time to make the connection does not mix with the back of the connection.

Why do we need four times and waved to disconnect

Because the relationship between full-duplex channels, the sender and recipient need to FIN packets and ACK packets, which means that the sender and receiver need twice waved to each, but one party is passive, it looked the so-called fourth wave.

The reason a large number of server status close_wait

In such cases the majority, BUG program, the connection is not released in the lead.

Or thread numbers in the thread pool is not configured reasonable.

UDP Introduction

1.UDP protocol is a non-connected, and a source terminal connected to resume free before transmitting data transmission time when he wants, simply fetch data from the application, as quickly as possible and to put it into the network, at the transmitting end, UDP data transmission speed, only the speed data generated by the application program, the computer limits the transmission bandwidth and capacity, at the receiving end, UDP segment to each message in a queue from the queue each time an application reading a message segment

2.UDP connection is not established, the connection state is not maintained, to support multiple clients while using the same transmission message.

3.UDP packet header only 8 bytes, compared to the TCP 20 bytes of information, the overhead is much smaller.

4. throughput without congestion control algorithm.

The best effort delivery, does not guarantee reliable delivery, no need to maintain complex link state table.

6. split or merge message-oriented, packet information is not submitted by the application.

Difference between TCP and UDP

They are two protocols in the transport layer of the OSI model, TCP provides reliable communication transmission, while UDP and commonly used in broadcasting and let the details of control to be layers of communication transmission

TCP is a reliable, the use of a handshake acknowledgment and retransmission mechanism provides a reliable guarantee, UDP may be lost.

The use of TCP sequence numbers to ensure the delivery of the order Izvestia, the disorder may be reached, but in the end hi order.

TCP slow slower than UDP, TCP because more work to do in order to ensure the reliability and resistance.

UDP is suitable for speed-sensitive applications, online video media, television broadcasting, online multiplayer games.

Data overhead size

HTTP

He is the application layer protocol, he was on a request response mode stateless protocols, often based on the TCP connection, the HTTP1.1 Keep Alive mechanism of release is given a continuous connection, the vast majority are WEB development WEB-based applications over HTTP protocol, his main features are:

1 ** Support client server model ** HTTP protocol over the work with the client server architecture, the browser sends a request URL to the HTTP server by HTTP client, the server sends a response to the server WEB server according to the received request information.

** 2. ** time simple and fast client service requests to the server only needs to transmit the request method (get / post) and path.

3. Flexible HTTP allows transmission of any type of data type,

  1. No connection limit value process each connection request, the client requests the server processed after the customer and receives a response that is disconnected. After a long connection using HTTP 1.1 by default, that is, the server needs to wait for some time after the disconnect to ensure connectivity features.
  2. Stateless When no protocol for transaction processing and memory capabilities, the lack of state means that if the subsequent processing required to transfer the information to be retransmitted, which may result in the amount of data is increased through each connection, on the other hand, does not require prior information server his response to fast.

HTTP protocol defines how the WEB client requests a WEB page from the WEB server, and the server how it WEB page to the client, the HTTP protocol using a request-response model, a client sends a request message to the server, the request message comprising a request method, URL, protocol version, header request data and requests, a server response status line, including the contents of the protocol version response, success or error code, the server information, the response information, and response data.

The following is a step of HTTP response:

1. The client connects to the server, establish a TCP socket connection,

2. sends an HTTP request, sends the request message to the server via a text TCP socket client,

3. The server receives the request and returns an HTTP response, WEB server receives the request, the resource location request, the server writes a copy of the resource is read by the client TCP socket,

4. Release the TCP connection.

5. Client to get relevant content and HTML parsing, first resolve the status line to see that the request is successful status code, and then parses each response headers, response headers warned of these is the need to parse an HTML document. Then parse HTML

What happened after the browser enter the URL, press Enter

1.DNS Analysis: First, the browser will query the DNS server cache layer by layer basis URL, parses the URL domain name corresponding to the IP address.

It will establish a TCP connection based on the IP address and the corresponding server port and 2. After the IP address is found, here it comes to the 3-way handshake.

3. Then read the file browser will issue an HTTP request, the request to the server

4 relative to the server in response to the browser request, the HTTP and HTML text with the corresponding response message back to the browser

The browser receives the response packet, assume that this request is successful, it will parse the HTML document rendered HTML page in the browser.

6. The browser release TCP connections, involving four wave

Talk about common HTTP status codes

Composed by the three-digit status code, the first definition of the appropriate category

1XX : indicates that the request has been accepted and is being processed

2XX : indicates successful acceptance of the request, appreciated received.

3xx : Redirection means that you need to do to fulfill the request further action

4XX : client error, request a syntax error, or the request can not be achieved

5XX : server error server failed to achieve a legitimate request

The difference between GET and POST

HTTP packet level : GET request to request information Where can URL, style information to key-value pairs exist in the link, and the POST request information in newspaper style, the requested information must be resolved to get the message. Security than Get, in fact, to resolve the POST request is very simple, so to solve the security problems still have to rely on HTTPS. (Packet capture on the line) Get request information have length restrictions, post no limit.
Here Insert Picture Description
Database level : Get the request meets idempotency and security, POST does not comply.

The first operation of the database and the results obtained are consistent with multiple operations, security refers to the operation of the database is not changed database data.

Get generally used as a query, generally in line with Idempotence and safety

POST requests to submit data to the database, thus changing the data in the database, followed by the results of each obtained POST requests are likely to be different. Because POST request is acting on the upper level of the URL, then every request will add new resources.

Get can be cached, POST requests can not : Get request can be cached browser, the browser can be saved as a browser bookmark, POST mode is not available.

The difference between Cookie and Session

Because the number of stateless HTTP, so we have time to log in each time you visit the demand, we must patiently enter the account password, but actually there is no such situation, since the introduction of the HTTP Cookie and Session with the state.

Cookie : the special information is the server to the client, the client is present in the form of text, to the server each time the client sends a request, will take this information. That is when a user uses a browser to access the Cookie support site, users can provide personal information, and submitted to the server, the server at the same time the prime minister immediately return hypertext client will send back personal information, such information and there is not a HTTP Response Body, but in the HTTP Response Head. When the browser receives such information, the browser will store this information in a single location after the service again sends personal information when required, will carry the information to the request header, the server receives again receive information with Cookie, the Cookie will be resolved and then do other operations to respond.

Session : is the mechanism the server, the server uses a similar hash table structure to hold the information, when the program needs to create a Session request for a client, the server first checks the client's request in whether already contains a Session identification , that is, Session ID, if you include the Session ID, then the previous Session has been created for the client, the server according to Session Session retrieved use it, if not retrieved, create a new one. If the request is no Session ID, then create the client a Session, and generates a Session ID associated with this, this is not a repeat there is no regular string, the Session ID will be sent back to the client in the response and save.

Session of implementation :

Cookie used to achieve, a postback JSESSIONID server to the client, when the client requests to saved time on the belt.

URL achieved using write-back: URL refers to all the linked server to the browser page, carries JSESSIONID parameters, so that the client is connected to the store so that future generations will carry on this. Here Insert Picture Description
Here Insert Picture Description
the difference:

A client, a server side.

Cookie unsafe, others may exist locally Cookie analysis.

If you consider to reduce the burden on the server, you should use Cookie

The difference between HTTP HTTPS

Here Insert Picture Description
SSL (Security Sockets Layer) Secure Sockets Layer

To provide a data integrity and security protocols for network communications

TCP and SSL is located between each application layer is the operating system external API, later renamed TLS SSL.

Using authentication and data encryption to ensure security.

** HTTPS data transport stream layer * range:

The browser supports encryption algorithm information to the server side,

Select the server browser supports encryption in the form of certificates of postback browser,

Browser verify the legitimacy of the certificate, a certificate and public key encryption in conjunction with the information sent to the server,

Server receives information, using the private key to decrypt information encrypted message are sent back in response to the browser.

Browser decrypts response information, and verifies the message, then the interaction data is encrypted.

Difference :

HTTPS required to apply for CA certificates, HTTP is not required.

HTTP ciphertext transmission, HTTP is expressly transmission

HTTPS default port 443, HTTP default port 80.

The default browser is filled HTTP, Web site using 301 or 302 jumps to HTTPS, this process uses HTTP, or will be hijacked.

You can use HSTS optimization.

Published 11 original articles · won praise 1 · views 592

Guess you like

Origin blog.csdn.net/Fujie1997/article/details/104823327