Finishing network programming interview questions (b)

1: What is C / S and B / S architecture?

C / S architecture software (i.e., a client / server model) client and server into two layers: the first layer is a bound on the client system indicating to the service logic, the second layer is formed by a combination of a network database server. Simply means that the first layer is a user presentation layer, the second layer is the database layer. The client and the server directly connected to these two components are plays an important role.

B / S structure of the first layer is a browser (i.e. the client) only simple input and output functions, the transaction processing logic very small part. Because customers do not need to install the client, as long as the browser will be able to browse the Internet, so it is intended for a wide range of users, the interface is designed to be relatively simple, common. The second layer is a WEB server, plays the role of information transfer. When a user wants to access the database, it will first send a request to the WEB server, sends a request to the database server to access the database server after reunification WEB request, the request is based on the SQL statement to achieve. The third layer is the database server, which kept the large amounts of data. When the database server receives a request WEB server, the SQL statement will be processed, and sends the results returned to the WEB server, the data results next, WEB server will receive conversion sent to the browser as HTML text.

 

2: What is the ARP protocol?

ARP (Address Resolution Protocol) is ARP . The most straightforward argument is: in Ethernet IP, when the upper-layer protocol to a contract, with the IP address of the node, ARP will be able to provide the MAC address of the node.

 

3: What is a local area network and wide area network?

Wide area network (WAN, public intranet, extranet), is what we usually refer to the Internet, it is a network all over the world. Local area network (LAN, private network, internal network), with respect to the wide area network (WAN), mainly refers to the computer network within a small range. This "small-scale" may be a family, a school, a company, or a government department. BT public network is often referred to, the external network, i.e., a wide area network (the WAN); BT often referred to private network, internal network, i.e., a local area network (LAN). To apply to a wide area network after each computer (or other network device) has one or more WAN IP address (or public network, external network IP address), WAN IP address generally pay to the ISP, WAN IP addresses can not be repeated; each computer (or other network device) has on a local area network (LAN) or a plurality of LAN IP address (or private network, an IP address), local IP address assigned to the internal LAN , IP addresses different LAN can be repeated and will not affect each other.

 

4: What is a socket brief socket communication process based on tcp protocol?.

Socket known as "socket", is a system to provide a method for network communications. It is not a protocol that does not specify how the computer should transmit information, but provides programmers with an interface to send messages, programmers a method using this interface, send and receive messages .Socket describes an IP port pair and which simplifies the operation of the programmer to know each other's IP and port can send messages to each other, then the messages sent by the server process, Socket contains the communication between the parties, namely the client and server.

socket procedure shown below.

General Procedure TCP server is programmed:   

1, to create a socket, a function Socket ();

SOCKET SocketListen = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);   

2, to set the socket attribute, a function setsockopt (); * Optional   

3, binding information of the IP address and port to the socket, with the bind function ();

SOCKET_ERROR = bind(SocketListen, (const sockaddr *) & addr, sizeof(addr))   

4, open the monitor, with the listen () function;

SOCKET_ERROR == listen(SocketListen, 2)   

5, is connected to receive customer served by Accept function ();

SOCKET SocketWaiter = accept(SocketListen, _Out_ struct sockaddr * addr _Inout_ int * addrlen);

6, send and receive data, a function send () and the recv (), or a read () and Write ();

7, off a network connection;

closesocket(SocketListen);

closesocket(SocketWaiter);

8, close monitor;

SOCK_STREAM This feature is connection-oriented, i.e., every connection must be established before the send and receive data via the connect, the communication network is such SOCK_DGRAM User Datagram Protocol protocol, which is connectionless and unreliable.

Programming TCP Client general steps are:   

1, to create a socket, a function Socket ();   

2, to set the socket attribute, a function setsockopt (); * Optional   

3, binding information of the IP address and port to the socket, a function bind (); * Optional   

4, set properties like IP address and port to be connected to each other;   

5, the connection server, a function Connect ();   

6, send and receive data, a function send () and the recv (), or a read () and Write ();   

7, closed network connection; intsend (_In_SOCKETs, // send to which socket, accept the returned socket _In_const char * buf, _In_ int len, _In_ int flags.);

 

5: What is the reason for socket stick package what caused the package is sticky stick package which case the phenomenon would happen???

Stick package: a plurality of data packets are stored continuously in a continuous buffer, when reading the data packet transmission can not be determined since the occurrence of the boundary side, while the use of a certain magnitude estimate for data readout, if both when the finger will not match size of several data packets sent by the sender to the recipient receives stick into a packet, from the receive buffer to see, after a first packet data immediately before the end of a data packet.

The reason for stick pack phenomenon is multifaceted, both may be caused by the sender, also may be caused by the recipient.

Induced viscosity packet sender is itself caused by the TCP protocol, TCP to improve the transmission efficiency, the sender often enough data collected after a packet data transmission. If the successive data transmission are small, usually to a TCP will transmit optimization algorithm in accordance with a synthesis of these data packets out, so that the receiving side receives the data packet sticky.

Stick package recipient is caused because the recipient user process is not timely receive data, resulting in stick pack phenomenon. This is because the data received on the first receiver system receiving buffer fetch process user data from the buffer, the previous data packet has not yet been removed if the user process the next data packet arrives, then the next data packet after the system is put to the front a data packet receive buffer, and the buffer size according to the user process receives preset data from the fetch buffer system, so that the time taken to multiple packet data.

Subcontracting refers to our sub-recipient to be managed as they arise stick package. (Will appear in the connection length) packet boundary misalignment occurs, resulting in erroneous data read sub, further distort the meaning of the original data.

1. When the case of short connection, regardless of the case where the stick package.

2. If no transmission data structures, such as file transfer, so that the sender just transmits, to the receiving side storage just received ok, do not consider stick package

3. If the parties to establish a connection, the connection needs to be sent within a period of time different data processing structures: Create a pretreatment recipient thread, the received packet is pretreated to separate adhesion packet

Note: there are two cases stick package, one is the packages are glued together complete packet, another case packages have stuck together incomplete packet.

 

6: What is a firewall and the role?

1. What is a firewall

Refers to the combination firewall installed in different networks (e.g., trusted and untrusted intranet public network) or a series of components between the network security domain. It can monitor, limit, change the flow of data across firewalls, as much as possible information for external shielding, structural and operating conditions within the network, in order to achieve security of the network. Logically, a firewall is a separator, a limiter, is a parser to effectively monitor any activities between the internal network and the Internet, to ensure the security of the internal network.

2. The benefits of using the Firewall

Protection of vulnerable service. Unsafe by filtering services, Firewall can greatly improve network security and reduce the risk of the host subnet. For example, Firewall can disable NIS, NFS service through, Firewall and can refuse source routing and ICMP redirect packets.

Control access to the system . Firewall can provide access control of the system. Such as allowing access to certain hosts from the outside, while prohibiting access to another host. For example, Firewall to allow external access to specific Mail Server and Web Server.

Centralized security management . Firewall on intranet centralized secure management, security rules defined Firewall can run on the entire internal network systems, without having to set up a security policy on the intranet each machine. Firewall can define different authentication methods, without the need to install a specific authentication software on each machine separately. External users need only authenticate once to access through the intranet.

Enhanced confidentiality. Use Firewall can prevent an attacker to obtain useful information network system attacks, such as Figer and DNS.

Records and statistical data and the illegal use of network utilization data . Firewall can be recorded and statistics through the Firewall, network communications, to provide statistics on network usage, and, Firewall can provide statistical data to determine a possible attack and detection.

Policy enforcement. Firewall provides the means to develop and implement a network security policy. When Firewall is not set, the network security depends on the users per host.

 

7: Differences select, poll, epoll model?

Please refer to the collection of the blog "several typical server network programming model for induction (select poll epoll)"!

Further processing is carried out by setting or checking the data structure stored on the select flag fd nature. Such shortcomings are caused by:

Number fd 1 can monitor the individual processes is limited;

2 need to maintain a large amount fd is used to store the data structure, so that the user can copy a large space and kernel space when passing the overhead structure;

3 of the socket is a linear scan to scan.

 The poll and select essentially no difference, the user would copy the array passed to the kernel space, and then query the status of each device corresponding to fd, if the device in the apparatus is ready queue and added to a traversal continues, if all traversed no device found fd ready, then suspends the current process until the device is ready or active timeout, wake it up again after traversing fd again. This process has undergone many unnecessary traversal. It does not limit the maximum number of connections, because it is based on a linked list to store, but also has a disadvantage: an array of a large number of fd is copied in its entirety between user mode and kernel address space, whether or not such copy is not a significance. poll also characterized by "trigger level", if reported fd, not processed, it will report the fd again next poll.

epoll support level trigger and edge trigger, the biggest feature is that edge-triggered, it only tells the process which has just become fd would need state and will notify once. On the replication issues we said before, epoll use mmap reduce replication overhead. Another feature is, epoll using the "event" readiness notification way through epoll_ctl registration fd, once the fd ready, the kernel uses a similar callback callback mechanism to activate the fd, epoll_wait can be notified.

Published 61 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_33204444/article/details/93651541