SDSU CS 580 Client-Server Programming
Fall Semester, 2002
    Lecture Notes Index    Next    
© 2002, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 03-Sep-02


Code Complete by Steve McConnell

Doc 1, Introduction Slide # 2

Course Introduction

Course Outline

Source Version Control
Client Development Issues
Network Basics
Server Types & Structure
Client-Server Protocols
Web based Applications
CGI, Fast-CGI, Servlets
Advanced topics

This outline will be changed during the semester.

Doc 1, Introduction Slide # 3
Main Points of Class

Common design issues & solutions for building a server

Issues in designing a client-server network protocol

Handling Concurrency

Accessing databases

Programming issues dealing with working on client-server code

Doc 1, Introduction Slide # 4
Programming languages for the Course


We will be using parts of JDK 1.4
NIO contains richer socket support

Smalltalk – VisualWorks 7

Improved code browsers & support for network programming

Doc 1, Introduction Slide # 5
What does it mean to “Know” Java or Smalltalk

Basic syntax of the language

Core API

No one knows the entire API of either language
You should have good grasp of the common or core API
Collections, Files, Exceptions, Streams

Language culture - Ways of doing things in each language

Object-oriented programming

Doc 1, Introduction Slide # 6

Introduction to Client-Server

What is Client-Server?

Application that initiates peer-to-peer communication
Translate user requests into requests for data from server via protocol
GUI often used to interact with user


Any program that waits for incoming communication requests from a client
Extracts requested information from data and return to client
Common Issues
  • Authentication
  • Authorization
  • Data Security
  • Privacy
  • Protection
  • Concurrency

Doc 1, Introduction Slide # 7

Example: World Wide Web (WWW)

Server normally provides data to clients
Often utilizes some data base
WWW data is HyperText Markup Language (html) files
Client Server Programming
<H2>Client Server Programming</H2>

Doc 1, Introduction Slide # 8

How the client and server interact
Glue that makes client-server work
Involves using low level network protocols and application specific protocols
Designing application specific protocols is very important
WWW uses the HyperText Transfer Protocol
   Request   =    SimpleRequest | FullRequest
   SimpleRequest   =   GET <uri> CrLf
   FullRequest   =   Method URI ProtocolVersion CrLf
         [*<HTRQ Header>]
         [<CrLf> <data>]
   <Method>   =    <InitialAlpha>
   ProtocolVersion   =   HTTP/1.0
   uri   =   <as defined in URL spec>
   <HTRQ Header>   =   <Fieldname> : <Value> <CrLf>
   <data>   =    MIME-conforming-message        

Doc 1, Introduction Slide # 9
Protocol Choices

Transmit ASCII or Unicode between machines
HTTP is common transport layer
XML becoming common
SOAP new XML standard

Transmit objects between machines
Faster development time
RMI, Corba are examples

Doc 1, Introduction Slide # 10
What this Course is not

An advanced (or beginning) Networking course

How to use a client builder application/system


What this Course covers

Skills & knowledge required to build client-server applications

Doc 1, Introduction Slide # 11

What Client-Server Requires of a Programmer

Doc 1, Introduction Slide # 12

Programming Issues

Naming Convention for Classes, Variables & Methods

First letter of each word capitalized except for the first word
Class names start with a capital letter

Doc 1, Introduction Slide # 13


"Finding good names is the hardest part of OO Programming"

"Names should fully and accurately describe the entity the variable represents"

What role does the variable play in the program?

Data Structure
Role, function

Some Examples of Names, Good and Bad

Velt, V, X, Train
CD, Current, C, X, Date
LPP, Lines, L, X

Names should be as short as possible and still convey meaning to the reader

Doc 1, Introduction Slide # 14


"Comments are easier to write poorly than well, and comments can be more damaging than helpful"
What does this do?

for i := 1 to Num do
 MeetsCriteria[ i ] := True;
for  i := 1 to Num / 2  do begin
 j := i + i;
 while ( j <= Num ) do begin
  MeetsCriteria[ j ] := False;
  j := j + i;
for i := 1 to Mun do
 if MeetsCriteria[ i ] then
  writeln( i, ' meets criteria ' );

Doc 1, Introduction Slide # 15
How many comments does this need?

for PrimeCandidate:= 1 to Num do
   IsPrime[ PrimeCandidate] := True;
for  Factor:= 1 to Num / 2  do begin
   FactorableNumber := Factor + Factor ;
   while ( FactorableNumber <= Num ) do begin
      IsPrime[ FactorableNumber ] := False;
      FactorableNumber := FactorableNumber + Factor ;
for PrimeCandidate:= 1 to Num do
   if IsPrime[ PrimeCandidate] then
      writeln( PrimeCandidate, ' is Prime ' );
Good Programming Style is the Foundation of Well Commented Program

Doc 1, Introduction Slide # 16

Commenting Paragraphs of Code

Write comments at the level of the code's intent

Comment the why rather than the how

Make every comment count

Document surprises

Avoid abbreviations

How verses Why


/* if allocation flag is zero */
if ( AllocFlag == 0 ) ...


/* if allocating a new member */
if ( AllocFlag == 0 ) ...

Even Better

/* if allocating a new member */
if ( AllocFlag == NEW_MEMBER ) ...

Doc 1, Introduction Slide # 17
Summary comment on How

{ check each character in "InputStr" until a 
  dollar sign is found or all characters have 
  been checked }
Done   := false;
MaxPos := Length( InputStr );
i      := 1;
while ( (not Done) and (i <= MaxLen) ) begin
   if ( InputStr[ i ] = '$' ) then
      Done := True
      i := i + 1
Summary comment on Intent

{ find the command-word terminator }
Done   := false;
MaxPos := Length( InputStr );
i      := 1;
while ( (not Done) and (i <= MaxPos ) ) begin
   if ( InputStr[ i ] = '$' ) then
      Done := True
      i := i + 1

Doc 1, Introduction Slide # 18
Summary comment on Intent with Better Style

{ find the command-word terminator }
FoundTheEnd      := false;
MaxCommandLength := Length( InputStr );
Index            := 1;
while ((not FoundTheEnd) and 
       (Index <= MaxCommandLength)) begin
   if ( InputStr[ Index ] = '$' ) then
      FoundTheEnd := True;
      Index := Index + 1;

Doc 1, Introduction Slide # 19

Commenting Data Declarations

Comment the units of numeric data

Comment the range of allowable numeric values

Comment coded meanings

   CursorX:      1..MaxCols;   { horizontal screen position of cursor }
   CursorY:      1..MaxRows;   { vertical position of cursor on screen }
   AntennaLength:   Real;   { length of antenna in meters: >= 2 }
   SignalStrength:   Integer;   { strength of signal in kilowatts: >= 1 }
   CharCode:      0..255;   { ASCII character code }
   CharAttib:      Integer;   { 0=Plain; 1=Italic; 2=Bold  }
   CharSize:         4..127;   { size of character in points }
Comment limitations on input data
Document flags to the bit level

Copyright ©, All rights reserved.
2002 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 03-Sep-02    Next