( Latest Revision: 
Sat Apr 7 00:53:33 PDT 2007
) 
 
Notes On Chapter Thirty
-- Example Of A Client And A Server
 
-  30.1 Introduction 
     
     -  In this chapter we see  explicit example code
	  that uses the socket API  to implement a simple client and a
	  simple server. 
      
 -  30.2 Connection-Oriented Communication 
     
     -  In connection-oriented communication the protocol software
	  establishes the connection. 
      -  In order to establish a connection applications at both ends must
	  execute commands directing actions of protocol software. 
      
 -  30.3 An Example Service 
     
     -   The idea of the example service is just to
	  count the number of client requests  received and report the
	  current count to each client. 
      -  This particular  example server is
	  connection-oriented.   
      
 -  30.4 Command-Line Arguments For the Example Programs 
      
     -  The server has an optional port parameter.  The default port is
	  5193. 
      -  The client has optional hostname and port parameters.  Default host
	  is localhost and default port is 5193. 
      -  While debugging, client and server can the same host -- just use the
	  defaults. 
      
 -  30.5 Sequence Of Socket Procedure Calls 
     
     -   Study the diagram on page 451 of the fourth
	   edition.   
      -  It illustrates the actions of the client and server. 
      
 -  30.6 Code For  Example Client  
     
     -  The code for the client starts on page 452 of the fourth edition.
	  
      -  In class,  I'll show on screen  the
	  comments I have in my copy of the text 
      
 -  30.7 Code For  Example Server  
      
     -  The code for the server starts on page 455 of the fourth edition.
	  
      -  In class,  I'll show on screen  the
	  comments I have in my copy of the text 
      
 
 -  30.8 Stream Service And Multiple Recv Calls 
     
     -   TCP guarantees only that data will be delivered
	  in order, with each call to recv() returning one or more
	  octets until all data has been received.  
      -  This accounts for the manner in which the 
	  client reads in a loop waiting for a return value of 0 bytes,
	   even though the server sends all the data across with one
	  call to  send()  
      
 -  30.9 Socket Procedures And Blocking 
     
     -  In Unix the calls to the socket operations are system calls.
	  
	  
	  -  They are requests for service to the operating system.
	       
	   -  It is  typical that client and server are
	       suspended (aka blocked) while the operating system performs
	       requested functions.   
           -  Most of the socket functions work this way. 
	   -  It's good that the programs block until the system calls
	       return.  There is nothing for them to do, and  they use up system resources like CPU time if
	       they are allowed to run while doing no productive work. 
	       
	   
	  
      -   The effect of the blocking is to 
	  synchronize  the client and server.   
      -   For example:  if the server is slow to
	  get to the part of the program where it does an  accept,
	  then the client just "sleeps" waiting to complete the call to 
	  connect().  This allows the server to "catch up" with the
	  client. 
      
 -  30.10 Size Of The Code And Error Reporting 
     
     -  The kind of error checking you see in the client and server code is
	  typical of "system programmer code." 
      
 -  30.11 Using The Example Client With Another Service 
     
     -   You can use either client or server with a
	  "wrong" correspondent!  Mix and match!   
      -  Use DAYTIME service (port 13 on many hosts) to test the client
	  independently of the server.  
      
 -  30.12 Using Another Client To Test The Server 
     
     -  You can use telnet to test the server independently of the client
	  (incidentally we did something like this earlier in lab when we
	  telnetted to the "sendmail" port 25 and delivered "fake" e-mail.
	  
      -   Example:  telnet zaurak.csustan.edu 5193
	    
      
 -  30.13  Summary