End aside how does the server pass arguments to the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: AXLINE); Fputs(buf, stdout); } Close(clientfd); exit(0); } code/net/echoclient.c Figure 12.27: Echo client main routine. After the loop terminates, the client closes the descriptor (line 23). This result in an end-of-file notification being sent to the server, which it detects when it receives a return code of zero from its readline function. After closing its descriptor, the client terminates (line 24). Since the client’s kernel automatically closes all open descriptors when a process terminates, the close in line 23 is not necessary. However, it is good programming practice to explicitly close any descriptors we have opened. Figure 12.28 shows the main routine for the echo server. After opening the listening descriptor (line 18), it enters an infinite loop. Each iteration waits for a connection request from a client (line 21), prints the 12.5. THE SOCKETS INTERFACE 637 domain name and IP address of the connected client (lines 23-27), and calls the echo function that services the client (line 29). When the echo routine returns, the main routine closes the connected descriptor (line 30). Once the client and server have closed their respective descriptors, the connection is t...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online