SDSU CS 596 Client-Server Programming
Comments on Assignment 4

[To Lecture Notes Index]
San Diego State University -- This page last updated March 5, 1996
----------


Issues

Passing Server Request to User
String  message  =  fromServer.readLine();

toUser.print( message );


Changing Server

Client loops, so made server loop
Comments

Need more why, less how

How
// Create the local stream
PrintStream  	toUser  	=  new  PrintStream( System.out );
ASCIIInputStream fromUser  = new ASCIIInputStream ( System.in );

Why
// Using ASCIIInputStream makes reading input easier
PrintStream  	toUser  	=  new  PrintStream( System.out );
ASCIIInputStream fromUser  = new ASCIIInputStream ( System.in );


How
// Create new socket
server  =  new  Socket( serverName, portNumber );
InputStream  fromServer  =  server.getInputStream();
OuputStream  toServer     =  server.getOutputStream();

Why
// Connect to server
server  =  new  Socket( serverName, portNumber );
InputStream  fromServer  =  server.getInputStream();
OuputStream  toServer     =  server.getOutputStream();

What is needed Here?
while ( true )  
{
    code deleted to save time



}
Command Line Parsing
class  CommandLineParser
    {

    /**
     * Returns true if command line contained the given option
     * Options are single characters
     * Argument is of form "P" where P could be any character 
     */
    public  Boolean  containsOption( String  option )


    /**
     * Returns true if command line contained all the given options
     * Each character in optionList is treated as a separate option
     */
    public  Boolean  containsOptions( String  optionList)


    /**
     * Returns string following given option
     */
    public  String  get(  String  option )

    }


Sample Code (not compiled)
class FirstClient
    {
    static  final  String  hostOption  =  "H";
    static  final  String  portOption  =  "P";

    public  static  void  main( String[]  args )
        {
        // Extract options from command line
        CommandLineParser  serverData;
        serverData  =  new CommandLineParser( args);

        if ( ! serverData.containsOptions( hostOption + portOption ) )
            properUsageReminder();

        String  hostName	= serverData.get( hostOption );
        String 	portString	= serverData.get( portOption );
        int	port	= Integer.parseInt( portString );

        // User exits loop via control C
        while  ( true )
            {
            // Connect to server
            Socket  server  =  new Socket( hostName, port );

            stuff not shown
            } // while
        } // main

    private static  void  properUsageReminder()
        {
            System.err.println(  "Usage: \n  java FirstClient " +
                portOption  + " serverPortNumber " + hostOption  + 
                " serverHostName" );
            System.exit( 0 );
        }
----------