03 Network programming

1. OSI seven-layer model and TCP/IP four-layer model?

Answer: The OSI seven-layer model: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer.

    TCP/IP four-layer model: network interface layer (physical layer, data link layer), Internet layer, transport layer, presentation layer (session layer, presentation layer, application layer).

2. What are the intervals of the four types of network addresses ?

Network addresses are divided into network bits and host bits.

Class A address: 1.0.0.0 --- 127.255.255.255 (127.0.0.1 is the loopback address) (ping the local loopback address means that the local protocol is fine)

Class B address: 128.0.0.0 --- 191.255.255.255

Class C address: 192.0.0.0 --- 223.255.255.255

Class D address: 224.0.0.0 --- 239.255.255.255 (broadcast address)

3. TCP server and client creation process

TCP server creation process : create communication file descriptor (socket) --> set port number and IP address (prepare for binding) --> bind (bind) --> listen ( listen ) --> accept Request, establish a connection (accept) --> send and receive messages (send/recv) --> close the file (close)

TCP client creation process : create a communication file descriptor (socket) --> set the port number and IP address --> initiate a connection request (connect) --> accept and send messages (send/recv) --> close the file (close)

4. UDP server and client creation process

UDP server-side creation process : Create a communication file descriptor (socket) --> set the port number and IP address (prepare for binding) --> bind (bind) --> accept and send messages (sendto && recvfrom )-->Close the file (close)

UDP client creation process : Create a communication file descriptor (socket) --> set the port number and IP address --> accept and send messages (sendto && recvfrom) --> close the file

5. What is the difference between TCP and UDP?

(1) TCP is a connection-oriented protocol, and UDP is a connectionless protocol.

(2) TCP requires more system resources, and UDP requires less system resources .

(3) TCP is a data stream mode, and UDP is a datagram mode.

(4) TCP guarantees the data sequence and data correctness, and UDP may lose packets.

6. Briefly describe the three-way handshake and four-way handshake

In the TCP/IP protocol, the TCP protocol provides a reliable connection service and uses a three-way handshake to establish a connection.

The first handshake: When the connection is established, the client sends a SYN (SYN = j) packet to the server, and enters the SYN_SEND state, waiting for the server's confirmation;

The second handshake: the server receives the SYN packet, must confirm the client's SYN (ACK = j+1), and at the same time send a SYN packet (SYN=k), that is, the SYN+ACK packet, at this time the server enters the SYN_RECV state;

The third handshake: The client receives the SYN+ACK packet from the server and sends a confirmation packet ACK (ACK=k+1) to the server. After the packet is sent, the client and server enter the ESTABLISHED state and complete the three-way handshake.

7. Wave four times

The process of waving four times ( the client or the server can initiate the waving action ) :

(1) Client A sends a FIN to close the data transfer from client A to server B. 

(2) Server B receives the FIN, and it sends back an ACK, confirming that the serial number is the received serial number plus 1.            

(Like SYN, a FIN will occupy a sequence number). 

(3) Server B closes the connection with client A and sends a FIN to client A. 

(4) Client A sends back an ACK message for confirmation, and sets the confirmation sequence number to the received sequence number plus 1.

Guess you like

Origin blog.csdn.net/weixin_45981798/article/details/129975938