Sorting out computer network interview questions
Let's review the installation and use mongodb
mongodb
- How to install
mongodb
- How to use
mongodb
- How to operate GO
mongodb
If you are mongodb
, you can check the article to know the installation and use of mongodb in GO
Let’s look at some interview questions today
Computer Network Interview Questions
network byte order:
Big-endian mode, low address stores high byte
local byte order:
Little-endian mode, low address stores low byte
three-way handshake
- Actively initiate the connection end and send the SYN flag to request to establish a connection. Carry serial number, data byte size (0), sliding window size
- The passive receiver sends a
ACK
response with a SYN flag. Carry serial number, data byte size (0), confirm serial number, sliding window size - Actively initiate the connection and send the
ACK
response, carrying the confirmation sequence number
waved four times
- Actively close the connection end and send FIN,
- Passively close the end, send
ACK
. - half closed - Passively close the end, send FIN
- Actively close the end, send
ACK
response-all connections are closed
third handshake fails in TCP? 16141ee61ecd06
ACK
is lost in the network at this time, after the timeout timer expires, the server will resend the SYN+ACK
packet
The number of /proc/sys/net/ipv4/tcp_synack_retries
is specified according to 06141ee61ecd45, and the default is 5
times
If after the specified number of retransmissions are reached, the ACK
response is still not received, then the server will automatically close the connection after a period of time
However, the Client thinks that the connection has been established. If the Client
end writes data to the Server
, the Server end will RST
Server
that the error of the 06141ee61ecd88 can be sensed.
When it fails, the server will not retransmit the ack
message, but directly send the RTS
message segment and enter the CLOSED
state
The purpose of this is to prevent the SYN
flooding attack
difference and advantages and disadvantages of long and short connections
Long connection: connection -> transfer data -> keep connection -> transfer data -> ………..->until one party closes the connection, most of the client closes the connection
Long connection refers to maintaining the connection regardless of whether it is used or not after the socket connection is established, but the security is poor.
- advantage
Long connections can save more tcp establishment/closing operations, reducing waste and saving time. For customers who frequently request resources, it is more suitable for long connections;
- shortcoming
With the increasing number of customers, the server will be unable to handle it sooner or later. At this time, it is necessary to adopt some strategies, such as closing some connections that do not perform read/write operations for a long time, so as to prevent some malicious connections from causing damage to server-side services. , If the conditions allow, you can use the client as the granularity to limit the maximum number of connections for each client
Short connection
Connection -> Transfer data -> Close connection
For example, HTTP is a stateless short link. Each time the browser and the server perform an HTTP operation, a connection is established, but the connection is terminated when the task ends.
- advantages:
Short connection is relatively simple for the server, the existing connections are all useful connections, no additional control is required
- drawback:
Frequent client connections will waste time on the establishment and closure of tcp
Sliding window
Sent to the peer connection, the real-time size of the buffer in this segment, to ensure that data will not be lost.
The return value of the read function in network communication:
- = 0
Indicates that the peer has closed the connection
- = -1
Determine the situation of errno
- errno == EAGAIN|EWOULDBLOCK
The non-blocking mode is set, when reading, the data has not arrived yet
- errno == EINTR
Interrupted by signal
- errno == other situations
abnormal
View port number
netstat -antp
Port reuse settings
int opt = 1;
setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(void *)&opt,sizeof(opt));
Half closed (FIN_WAIT_2)
Terminating a connection requires 4 times handshake
This is caused by TCP half-closed (half-close)
CLOSE_WAIT
status of the problem
The parent process opens socket
, and then uses the derived child process to process the business. The parent process continues to monitor network requests and never terminates
When the client sends FIN
, the read of the child process that handles the business returns 0, and the child process finds that the opposite end has been closed, and directly calls close() to close the local end.
In fact, just socket
the reference count of socket
not closed. As a result, there is an additional socket of CLOSE_WAIT
. .
avoid the above situation?
The closing processing of the child process should look like this:
shutdown(sockfd, SHUT_RDWR);
close(sockfd);
In this way, the FIN of the server will be sent out, and the socket will enter the LAST_ACK
state. Waiting for the ACK
, you can enter the initial state CLOSED
shutdown() function description
linux
system uses the shutdown
system call to control the way the socket is closed
int shutdown(int sockfd,int how);
The parameter how
allows to select the following methods shutdown
- SHUT_RD
Close the reading end of the connection. That is, the socket no longer accepts data, and any data currently in the socket receiving buffer will be discarded. The process will not be able to issue any read operations to this socket. Any data received after this call to the TCP socket will be confirmed and then discarded.
- SHUT_WR
Close the write side of the connection.
- SHUT_RDWR
It is equivalent to calling shutdown
twice: first with SHUT_RD, then with SHUT_WR
Note:
In multi-process, if one process is shutdown(sfd, SHUT_RDWR)
, other processes will not be able to communicate, if one process close(sfd)
will not affect other processes
2MSL
Duration TIME_WAIT
It must appear on the actively closed end to ensure that the last ACK
peer can receive it.
1. TTL
is 06141ee61ed647?
TTL is the abbreviation of Time To Live
This field specifies the maximum number of network segments IP
packet is discarded by the router.
TTL is 8 bit
field IPv4
packet header.
2. The role of TTL
The function of TTL is to limit the time that the IP
data packet exists in the computer network.
The maximum value of TTL is 255, and a recommended value of TTL is 64
3. TTL
Principle
Although TTL
literally translated, it is the time to survive, but actually TTL is IP
data packet can forward in a computer network.
TTL
field is set by the IP
packet, on IP
packet from the source to the destination
Each time the router passes through a router, the router will modify the TTL
field. The specific method is to reduce the TTL value by 1, and then forward the IP
If the TTL is reduced to 0 before the IP
packet reaches the destination IP
IP
`packet with TTL=0 and send an ICMP` timeout message to the sender of the IP
c/s model and b/s model
c/s model
advantages:
C/S is that it can realize complex application structure, high security and fast data transmission speed.
- Simple structure.
- Support distributed, concurrent environment. Effectively improve the utilization and sharing of resources.
- The server centrally manages resources, which is conducive to authority control and system security.
- Scalability is good. Both client and server can be upgraded separately
Disadvantages:
- Difficult to deploy (install the client one by one, choose the platform)
- Difficulty in maintenance (clients need to pay attention to updates)
- Heavy development workload
working process
- Open a communication channel to inform the server that the host where the server process is located will accept client requests on a certain port
- Waiting for the client's request to arrive at this port
- The server receives the service request, processes the request and sends a response
- Return to step 2, wait and process another customer’s request
- Shut down the server
b/s
model
Advantages:
B/S
is that it can be operated anywhere without installing any special software. As long as there is a computer with Internet access,
client has zero installation and zero maintenance. The expansion of the system is very easy.
Distributed, easy to expand, strong sharing
Compared with the traditional C/S
advantages:
- 1. Easy to deploy (each platform comes with a universal browser)
- 2. Easy to maintain (change the content of the webpage on the server side to realize the synchronous update of all users)
- 3. The page is dynamically refreshed, and the response speed is significantly reduced.
- Small development workload
Disadvantages:
- Cannot cache large amounts of data
working process
- The user makes a
HTTP
requestWeb
server through the browser. Web
server calls the corresponding file according to the browser request, and after not processing or interpreting the corresponding file, it returns the result of the code ofHTML
- The browser receives the page content (pure
HTML
Web
server and displays it to the user.
ping process and ICMP
protocol
process example
- Computer A (192.168.2.135) initiates a ping request, ping 192.168.2.179
- Computer A broadcasts the
ARP
request to query the MAC address of 192.168.2.179. - Computer B responds to the
ARP
request and initiates a one-way response to computer A, telling computer A that its MAC address is90:A4:DE:C2:DF:FE
- After knowing the MAC address, start the real ping request. Since computer B can know the source MAC address according to the request sent by computer A, all can respond according to the source MAC address.
The ping command is based on the ICMP
protocol. The ICMP
protocol exists to more efficiently forward the IP
datagram and improve the chance of successful delivery.
In addition to relying on ICMP
ARP
protocol in the local area network. The ARP
protocol can find out the computer's MAC address based on the IP
ARP
has a cache. In order to ensure ARP
, the computer will update the ARP
cache.
ICMP
ICMP
is (Internet Control Message Protocol) Internet control message protocol.
ICMP protocol is a connectionless protocol. It is a sub-protocol of the TCP/IP protocol suite and is used to transfer control messages between IP hosts and routers. ICMP is a network layer protocol.
The main functions are:
- Confirm
IP
package successfully reached the target address - Notify the reason why the
IP
packet was dropped during the sending process
Summarize
- Three handshake of computer network, four wave of hands
- What will happen if the third TCP handshake fails
- Advantages and disadvantages of long and short connections
- After sliding
read
function in network communication- What is half closed
- C/S model and B/S model
ICMP
Friends, writing is not easy
Your support and encouragement are my motivation to keep sharing and improve quality
Okay, that's it for this time
Technology is open, and our mindset should be more open. Embrace the change, live toward the sun, and work hard to move forward.
I am little magic boy , welcome to like and follow the collection, see you next time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。