Network programming interview point

1 , briefly OSI seven layer protocol. 

    The application layer, presentation layer, session layer, transport layer, network layer, data link layer, physical layer, 
    the application layer: user perceived 
    data link layer: defines the grouping of the electric signal. There is an Ethernet protocol. 
    Ethernet predetermined internet protocol device must have access to the card, the transmission and receiving ends of the address is the address of the NIC. 
    Network layer: presence ip protocol: Protocol predetermined network address. Which is defined as the ip address address, widespread adoption of ipv4 addresses. Network addresses are 32-bit binary composition. Arp protocol exists to convert the ip address of the target host for the mac address. 
    Transport Layer: establishing a communication port to port. 0 -65535 port range. 0- 1023 occupation of the port system. There is agreement tcp, udp protocol. 
    
    
    
    
    
    
2. What is the C / S and B / S architecture? 

C / S: architecture between a client and a server, install the application on the client. 
Characterized by a strong interaction, fast response. But the need for different different operating systems software development, 
coupled with faster product updates, program Iterative very often. 



b / S: architecture between the browser and server 
    features: distribution and strong, easy maintenance, development of simple, shared and strong, low cost of ownership. But it will involve a lot of interaction between the browser and the server, the communication cost is large, and issues related to data security, data transmission speed and other issues. 


3 , brief three-way handshake, four wave processes. 

    Three-way handshake:
    First, the client requests to establish a connection, the SYN =. 1, the transmission of packet number = SEQ X 
    a second time, the server reply message the ACK =. 1, the representative get request data, but also to establish a connection request, SYN = 1, the transmission packet number is = SEQ Y 
    third, the client reply message the ACK = 1, packet number transmitted to seq = x + 1 
    
    four wave: 
    first, a client request to disconnect, FIN = 1, the packet is transmitted SEQ = U 
    second, the server receives the request, replies the ACK = 1, packet number is transmitted SEQ = V 
    third, the server need to request to disconnect, the FIN = 1, the packet number sent to = seq w 
    fourth, the client receives a request, reply ACK = 1, data packets sent = U + 1 is seq 


4 , what is the arp protocol? 

arp is the acronym ARP. The so-called address resolution, is the host before sending the frame target ip address mac address of the conversion process of targeting. That target device through the ip address, query the target device's mac address, in order to ensure the successful completion of communication. 


5 , the difference between TCP and UDP?
    . 1 ), TCP is a connection-oriented connection is required prior to transmission data; UDP connection need not be established before the data transmission
     2), Although the tcp data transmission will stick package, but no data loss, data can be said to be safe; udp is to ensure reliable delivery of data as much as possible
     3 ), byte-oriented stream tcp udp-oriented message, no congestion control , so in a lot of use in real-time applications, such as video calls
     4 ), each tcp connection can only be point to point, udp support of many, many to many situations. 




7 Why tcp protocol-based communication is more reliable than the udp-based communication protocol? 

    tcp when transmitting data, the transmitting end transmits data to put in its cache, and then transmits the protocol control data to the cache of the peer, the peer returns an ACK =. 1, the transmitting side to clean up its own cache, the peer returns an = ACK 0, the re-transmission data, so tcp reliable. 
    Udp and when data is transmitted, the peer returns an acknowledgment message is not therefore unreliable. 


8 , what is the socket? DESCRIPTION socket-based communication protocol process tcp. 

    It is a socket abstraction layer between the application layer and the transport layer, he TCP / IP complicated operations abstract supply with a few simple interface layer calls, interprocess communication is achieved in the network. 
    Server: create socket, bind listening port number port ,,, ,, receiving client requests 
    to read a byte, transmitted byte close the passage; 
    Client: create socket, connect port designated computer, the write data is read close the channel. 
    

9 , what is the stick package? What are the reasons socket caused stick package is? Stick package which case the phenomenon occur?

    Stick package refers; when we create a tcp the socket, the kernel will create a transmit buffer and a receive buffer. When the number of bytes sent is too long, it will be sent to the plurality of split tcp packets, if the number of bytes transmitted continuously too short, will be waiting in a buffer, waiting for buffer is almost full, or until they are better made in the past. Because of the existence of such a buffer mechanism at the receiving end, if you wait until the buffer is full and we have to begin receiving data, several tcp data may already exist, or the recipient a chance to receive packet buffer, in which case it will cause problems stick package. 
    

    
    Reason: the recipient does not know the limits between the message, does not know how many bytes of data are extracted as a result. tcp protocol itself to improve the transmission efficiency, the sender will often lead to collect enough data to transmit after a tcp segment. If few data continuously transmitted, these data will tcp after the synthesis over a tcp segment transmission time in accordance with the optimization algorithm, so that the receiving side receives the data packet sticky. 
    
    
    What happens: 
    Case 1: the transmitting side send out only until the buffer is full, resulting in stick package, continuously transmitted, the amount of data 
    each time is small; 
    Case 2: reception packet buffer receiving end too late, resulting in a plurality of packets is received along receive. Or a received data is too small, next time have to take the last remaining data from the buffer. 
    
    The solution viscosity of the package: 
    
    For fixed-length packets, it is necessary to a given fixed length; using struct module to realize 
    for variable length packets can be explicitly given symbol boundary position of the end package. 

    
   
11 , What is a firewall and the role? 

    As a security system for a computer network. 
    Role: flowing through its network scan, you can filter out some attacks. 
    Can block specific ports out of communication, prohibit access from specific sites. 
    


twenty one, The difference between routers and switches? 

    Router can automatically assigned to the virtual LAN ip dial 
    switch data network for distributing only 
    
    router in the network layer may be processed according to TCP router address ip address / the IP protocol 
    switch can not, in the relay layer, according to the mac address addressing 
    
    can router put a ip assigned to multiple hosts using external ip show only a 
    switch can connect to multiple hosts, each with its own outside ip 
    
    router can provide firewall, switches do not provide this functionality
    

 22 , What is DNS? 

    That translates domain names to ip

 24 , producer-consumer scenarios and advantages of the model? 


Analysis:

 1 ), data processing is time-consuming, thread-exclusive, production data does not even feedback. 
The reason is the thread exclusive, because the thread is not in the queue queue, the order is unknown, there is a problem will involve strict order, for example, written to the log. 
2 ), producers of consumer use patterns in concurrent programming can solve most of the concurrency issues, the overall pattern to increase the speed of data processing programs by balancing production and the ability to work thread consumption thread. 


Scene: Based producer-consumer model area 

after the scene to deal with a longer mission time, upload and processing, the user can upload files to the system, the file system thrown into the queue, (tell the user to upload immediately return success, ?? ? 1  )
consumers to remove the queue file handling, such as (calling a remote interface to query data ???2 ) 
require tens of seconds, then it can provide an interface application for a query if the query remote service interface, (the interface to the application you want to put the database query tasks, ??? 3 ) 
and the interface to return immediately. Then treated with server access applications and tasks polling thread, after processing a message to the caller, so the caller to call again another interface to get data. 

Premise: the whole logic can be achieved? 

Question 1: If that users upload to see the success of the word, immediately want to see from the uploaded files, how to do? Or that in a given demand, it does not allow users to instantly view the file upload. Or that, whether these files directly into their browser cache to meet the needs of customers can not wait to look at? 

Solution: inclined to look into the browser cache 
if the data is not saved successfully, then give him hang, continue to the next 


question 2: Call remote interface is a concept? It can be understood: In addition to a backend server sends a request, the results found, it immediately returns a result. If, as mentioned in the text, time takes a long time, this remote interface to query task queue to go into asynchronous, when it got the results, go to the calling interface to send a request before informing a result, this also does not require a question 3. 

Answer: mainly because of the time needed to save longer, but still recommended to implement asynchronous query in the queue to go. 


Question 3: If you must use this case to go see the poll results. But I do not understand is that you can apply the task into the database? The database should not only read and write role in it, but also with the function performed by this logic? 
ANSWER: The database has stored procedures, functions, so there is a task to perform. 



Decoupling, no direct communication between the two, to communicate via a blocking queue, the equivalent of a buffer. 

 , what is cdn?25 , What is load balancing?

    Technology used to shorten the delay. Content delivery network. 
    Is to use a lot of cache server, users on the cloth relatively concentrated areas or ask your network. 
    When users access, using one global load technology, the user's request to access the server from the past, similar to the local warehouse Jingdong. 

26 , and LVS is what effect? 

    Linux is a virtual server. One of Dr. open source project. It has become part of the linux kernel. Mainly used for load balancing multiple servers. 

27 , Nginx and what is the role? 

Is a high performance http and reverse proxy server. Characterized occupy less memory, high concurrency. 

1 ), used to achieve reverse proxy, the request to the proxy server, to acquire data within the network, and then returned to the client prior to the request.
2 ), load balancing, in the case of high concurrent data traffic to share the multiple servers, each server to reduce the pressure. Cluster together to complete tasks.
3 ), to achieve separation of static and dynamic, the dynamic and static requests requesting separated. Depending on the configuration forwards do different for different requests. This is the basis of the separation movement. 


28 , keepalived and what role? 

Remain viable, it should be a piece of software to maintain high availability in the network. 

29 , HAProxy is and what role? 
Also provide high availability, load balancing application agent software. 


3031
    In the case of high concurrent data traffic apportioned to multiple servers, each server to reduce the pressure. By the cluster together to complete tasks. 

What is rpc and application scenarios? 
    A remote procedure call protocol.

 

Guess you like

Origin www.cnblogs.com/changwenjun-666/p/11470191.html