Multiple choice

1.TCP is called Transmission Control Protocol. It is a (D)

A transport layer unreliable protocol B application layer reliable protocol C application layer unreliable protocol D Transport layer reliable protocolCopy the code

2. How many binary digits does an IP address consist of? (c)

A  128        
B  48        
    C  32        
D  4
Copy the code

3. How many binary digits does the subnet mask of the IP address consist of? (c)

A  128        
B  48        
    C  32        
D  4
Copy the code

4. What is the function of the subnet mask of the IP address (D)

A Identifies the size of the IP address. B Identifies the type of the IP address. C Identifies the network bit and the host bit in the IP addressCopy the code

5. The address of a company’s network is 202.110.128.0/17.

A.202.110.44.0/17 B. 202.110.162.0/20 C. 202.110.144.0/16 D. 202.110.24.0/20Copy the code

6. In a multi-process concurrent server, a common problem to be solved is how to control and handle the communication and data exchange between different processes. Which of the following is not primarily provided by Unix systems d

A pipe B socket C message queue D mutexCopy the code

7. The following protocols that are not application-layer protocols are (a)

    A  UDP          
B  SNMP          
C   TELNET              
D  HTTP 
Copy the code

8. (A) To do STH.

A converts A long integer on the local machine to A long integer on the network B converts A short integer on the local machine to A short integer on the network C converts A long integer on the network to A long integer on the computer D converts A short integer on the network to A short integer on the computerCopy the code

9.172.16.1.1/14 What type of IP address does this IP address belong to (b)

A A B B C C DCopy the code

10. In the physical layer, specify the shape and size of the connectors used for the interface, the number and arrangement of leads, the characteristics of the holding and locking devices, etc. (c)

A electrical characteristics B functional characteristics C Mechanical characteristics D process characteristicsCopy the code

11. What kind of communication is a communication in which both parties can send and receive information at the same time (b)

A simplex communication B Full duplex communication C Half duplex communication D Pipe communicationCopy the code

12. Which of the following basic problems is not a basic problem of the data link layer (c)

A frame encapsulation B transparent transmission C error control D flow controlCopy the code

13. Pipeline is a common IPC mechanism and simplex. If two processes are to do bidirectional transport, (a) pipes are required

A. two B. three C. four D. oneCopy the code

14. What are the two parts of an IP datagram? (b)

A header and tail B header and data C Data and tail D header and tailCopy the code

15. The number of the port bound to FTP is (c).

A.152.5b. 152.5C. 152.5DCopy the code

16. Which of the following is not an important attribute of a subnet mask (d)

When exchanging routing information with neighboring routers, router A must inform the neighboring routers of the subnet mask of its network (or subnet). In addition to the destination network address, each item in router B's routing table must also give the subnet mask of that network. C If a router is connected to two subnets, it has two network addresses and two subnet masks. D The subnet mask can promote the stability of the data flow.Copy the code

17. Unix systems provide three ways to support concurrency. Which of the following is not one of these three ways (d)

A process B thread C I/O multiplexing D FIFOCopy the code

18. What are the two general categories of communication modes between programs running on end systems at the edge of the network (a)

A C/S and B/S modes B C/S and M2M modes C C/S and P2P modes D M2M and P2P modesCopy the code

19. TCP/IP is a four-tier architecture. Which of the following is not a hierarchy in this architecture?

A Application layer B Transportation layer C Network layer D Data link layerCopy the code

20. Which of the following layer needs to add a tail when sending data (c)

A Transport layer B Network layer C Data link layer D Physical layerCopy the code

21. The following incorrect understandings of the signal are (b)

Signal A is an asynchronous communication mode. Signal B is used only for user space process communication and cannot interact with kernel space. Signal C can be masked and signal D is implemented by soft interruptCopy the code

22. In the Internet, a triplet can uniquely identify an application layer process globally, which does not include (a)

A. Network layer protocol B. Address C. Port number d. Transport Layer protocolCopy the code

23. The characteristics of TCP do not include (c)

A. Connection-oriented B. Full-duplex data transfer C. Fast transmission speed D. Byte stream orientedCopy the code

25. Which of the following request methods does not include (b)

A.Post               
    B.Update 
C.Get                
D.Head
Copy the code

26. The design architecture of P2P does not include one of the following? ( c )

A. centralized architecture B. Fully distributed architecture C. Point-to-point architecture D. Hybrid architectureCopy the code

27. The command to test connectivity between network devices is (a).

    A :ping  
B: ifconfig  
C :traceroute  
D: netstat
Copy the code

Fills up the topic

1. URL communication uses the (URL) protocol, and TCP communication uses the (TCP) protocol. UDP Communication uses the (UDP) protocol.

SOCKET s, const struct sockAddr FAR *addr, int namelen struct sockADDR FAR *addr

Int Socket (intDomain,int type,int protocol); , domain parameters are protocol cluster and address cluster, and determine the set of protocols used by the socket. PF_UNIX stands for (Socket family protocol family), PF_INET for (protocol family), and PF_INET6 for (address family definition).

4. For TCP sockets, address information includes (IP) and (port number).

If (listenfd = socket(AF_INET, (SOCK_STREAM), 0) == -1){if (listenfd = socket(AF_INET, (SOCK_STREAM), 0) == -1){ .}

6. What do the following three statements do

server.sin_family=AF_INET; (Server side starts to establish socket descriptor)

server.sin_port=htons(PORT); (Ensure byte order)

server.sin_addr.s_addr = htonl (INADDR_ANY); (Listen to all addresses of clients)

7. In order to ensure data integrity in threads, we usually use a mechanism (data integrity).

8. In the multi-process server, please add the missing part of the program

pid_t pid; ..................... if (( PID=FORK() )>0) { close(connectfd); continue; } else if ((PID) = =0) {close(listenfd); process_cli(connectfd, client); exit(0); } else { printf("fork error\n"); exit(0); }Copy the code

9. Each thread has its own: thread ID, stack, entity, object.

10. The transport protocol does not require connection (UDP) to be faster than TCP.

11. Digital signature is private key encryption and (public key) decryption.

12. The local echo address is (127.x.x.x).

13. In SMTP, an E-mail consists of three parts (envelope, header and body).

Short-answer questions

1. Brief description of TCP socket communication structure flow (server and client)

2. Bind the listening socket to the local IP address and port 3. 4. Wait and accept connection requests -> Default blocking function 5. Communication; 6. Close the socket client: 1. Create a socket for communication 2. Communication 4. Close the connectionCopy the code

2. Describe the differences between threads and processes.

Process: narrow definition: process is the execution process of a program, is the basic unit of resource allocation and scheduling system. Thread: an execution path in a process. It is the smallest unit in which the operating system can schedule operations.Copy the code

3. Describe the major differences between TCP and UDP.

TCP is connection-oriented. UDP is connectionless TCP. It provides reliable services. UDP does its best to deliver, that is, it does not guarantee reliable delivery. The transmission efficiency of TCP is relatively low. UDP transmission efficiency TCP connections can only be point-to-point or one-to-one. UDP is supported byCopy the code

4. List some important features of IP addresses.

A hierarchical address structure. An IP address is the interface that identifies a host and a link. When a host can connect to multiple different networks, the host has multiple IP addressesCopy the code

5. What is a port and why are ports introduced in network communication?

In the TCP/IP protocol cluster, a port is the communication interface between the application layer process and the transport layer protocol entity. During network communication, a port needs to uniquely identify the endpoints on both ends of the communication. That is, a port is used to identify the application programs running on a host.Copy the code

What is a socket?

The abstraction of endpoints for two-way communication between application processes on different hosts in the network is the interface through which applications interact with the network protocol rootCopy the code

Comprehensive word problems

1. Design a TCP two-way communication program based on Linux system

#define IPADDRESS "127.0.0.1" #define PORT 8848 #define BUF_SIZE 1024 void* SendMes_Thread(void* Arg) { puts("Thread created."); Int * Client_Socket=(int*)Arg; char Mes_Buf[BUF_SIZE]={0}; while(1) { scanf("%s",Mes_Buf); Send (* Client_Socket Mes_Buf, strlen (Mes_Buf) + 1, 0). bzero(Mes_Buf,BUF_SIZE); } close(*Client_Socket); return NULL; } int main(int Argc,char** Argv) {// Create server socket int Server_Socket=socket(AF_INET,SOCK_STREAM,0); if(-1==Server_Socket) { perror("Server socket creation failed!" ); return -1; } struct sockaddr_in Server_NetInfo={0}; Server_NetInfo.sin_family=AF_INET; Server_NetInfo.sin_addr.s_addr=inet_addr(IPADDRESS); Server_NetInfo.sin_port=htons(PORT); If (-1==bind(const struct sockAddr *)&Server_NetInfo,sizeof(struct sockAddr))) {perror("Binding" failure!" ); return -1; } if(-1==listen(Server_Socket,6)) {perror("Linstening the to failure!" ); return -1; } socklen_t Client_NetInfoSize=sizeof(struct sockaddr_in); Struct sockaddr_in Client_NetInfo={0}; struct sockaddr_in Client_NetInfo={0}; Int Client_Socket=-1; // Create client socket int Client_Socket=-1; Client_Socket=accept(Server_Socket,(struct sockaddr*)&Client_NetInfo,&Client_NetInfoSize); if(-1==Client_Socket) { perror("Accepting fainure!" ); } // Create a thread to send messages pthread_t Thread_ID=-1; if(-1==pthread_create(&Thread_ID,NULL,SendMes_Thread,(void*)&Client_Socket)) { puts("Create thread falied!" ); return -1; } char Mes_Buf[BUF_SIZE]={0}; while(1) { if(0==recv(Client_Socket,Mes_Buf,BUF_SIZE,0)) { puts("Client is desconnected!" ); break; } printf("Client: %s\n",Mes_Buf); } close(Server_Socket); return 0; }Copy the code
#define IPADDRESS "127.0.0.1" #define PORT 8848 #define BUF_SIZE 1024 # RecvMes_Thread(void* Arg) {int* Client_Socket=(int*)Arg; char Mes_Buf[BUF_SIZE]={0}; while(1) { if(0==recv(*Client_Socket,Mes_Buf,BUF_SIZE,0)) { perror("Server is disconnected!" ); break; } printf("Server: %s\n",Mes_Buf); } close(*Client_Socket); return NULL; } int main(int Argc,char** Argv) {// Create client socket int Client_Socket=socket(AF_INET,SOCK_STREAM,0); if(-1==Client_Socket) { perror("Client socket creation failed!" ); return -1; } printf("Client_Socket==%d\n",Client_Socket); Struct sockaddr_in Server_NetInfo={0}; struct sockaddr_in Server_NetInfo={0}; Server_NetInfo.sin_family=AF_INET; Server_NetInfo.sin_addr.s_addr=inet_addr(IPADDRESS); Server_NetInfo.sin_port=htons(PORT); If (-1==connect(Client_Socket,(const struct sockaddr*)&Server_NetInfo,sizeof(struct sockaddr_in))) { perror("Connecting failure!" ); return -1; } pthread_t Thread_ID=-1; if(0==pthread_create(&Thread_ID,NULL,RecvMes_Thread,(void*)&Client_Socket)) { puts("Create thread failed!" ); } char Mes_Buf[BUF_SIZE]={0}; while(1) { scanf("%s",Mes_Buf); If (1 = = send (Client_Socket Mes_Buf, strlen (Mes_Buf) + 1, 0)) {perror (" Sending failure!" ); break; } bzero(Mes_Buf,BUF_SIZE); } close (Client_Socket); return 0; }Copy the code

2. Design a multithreaded server program based on Linux system

{while(1) {recv(...)}} ; process(...) ; send(...) ; } close(...) ; } main( socket(...) ; bind(...) ; listen(...) ; while(1) { accept(...) ; pthread_create(); }}Copy the code

3. Design a UDP two-way communication program based on Linux system

#define PORTNO 60000 #define PORTS 56666 #define MSGSIZE 128 int main( void ) { int sfd,ret,len,sfd1; struct sockaddr_in st, cst; char msg[MSGSIZE]; len = sizeof(struct sockaddr); sfd = socket( AF_INET, SOCK_DGRAM, 0); memset( &st, 0x0, len ); st.sin_family = AF_INET; St.sin_addr. S_addr = inet_ADDR ("192.168.36.129"); st.sin_port = htons(PORTNO); ret = bind( sfd, (struct sockaddr *)&st, len ); len = sizeof(struct sockaddr); sfd1 = socket( AF_INET, SOCK_DGRAM, 0); memset( &cst, 0x0, len ); cst.sin_family = AF_INET; //IPV4 protocol family cst.sin_addr. S_addr = inet_ADDR ("192.168.36.129"); Cst.sin_port = htons(PORTS); While (1){ret = recvfrom(SFD, MSG, MSGSIZE, 0, (struct sockAddr *)&st, (socklen_t *)&len); msg[ret]=0x0; Printf (" the server received data from the client as :[%s]\n", MSG); // Send server data char BUFF; scanf("%s",&BUFF); strcpy(msg,&BUFF); sendto( sfd1, msg, strlen(msg),0, (struct sockaddr *)&cst, (socklen_t)len ); } return 0; }Copy the code
#define PORTNO 60000 #define PORTS 56666 #define MSGSIZE 128 int main( void ) { int sfd,sfd1,ret,ret1; struct sockaddr_in st,cst; size_t len; char msg[MSGSIZE]; len = sizeof(struct sockaddr); sfd = socket( AF_INET, SOCK_DGRAM, 0); memset( &st, 0x0, len ); st.sin_family = AF_INET; St.sin_addr. S_addr = inet_ADDR ("192.168.36.129"); st.sin_port = htons(PORTNO); Len = sizeof(struct sockaddr); sfd1 = socket( AF_INET, SOCK_DGRAM, 0); memset( &cst, 0x0, len ); cst.sin_family = AF_INET; //IPV4 protocol family cst.sin_addr. S_addr = inet_ADDR ("192.168.36.129"); cst.sin_port = htons(PORTS); ret = bind( sfd1, (struct sockaddr *)&cst, len ); char BUFF; while(1){ scanf("%s",&BUFF); strcpy(msg,&BUFF); sendto( sfd, msg, strlen(msg),0, (struct sockaddr *)&st, (socklen_t)len ); ret = recvfrom( sfd1, msg, MSGSIZE, 0, (struct sockaddr *)&cst, (socklen_t *)&len ); msg[ret]=0x0; printf("results:[%s]\n", msg); } return 0; }Copy the code