Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Client/Server Design

Similar presentations


Presentation on theme: "Introduction to Client/Server Design"— Presentation transcript:

1 Introduction to Client/Server Design
CSCI 392 Java Programming Dr. Dannelly

2 Standard Client/Server Design
main server process client initial handshaking request messages response messages server subprocess

3 Web Example Client (Web Browser) connect to port 80 of the machine
send the formatted request read reply Server Child read request if file exist send file contents else send "404 not found" Web Server for(;;) wait for connection create child to handle request

4 HTTP message formats Request Message Reply Message
GET /path/file HTTP/1.0 misc headers blank line Reply Message HTTP/ OK Content-Length: 3731 Content-Type: text/html Last-Modified: Tue, 16 Aug :10:01 GMT Accept-Ranges: bytes ETag: "6178b5dc585ccc1:1819e" Server: Microsoft-IIS/6.0 MicrosoftOfficeWebServer: 5.0_Pub X-Powered-By: ASP.NET Connection: close <html> <head> <title>Steve Dannelly</title>

5 Sample Client Code // connect to the server
Socket sock = new Socket ("faculty.winthrop.edu",80); // get the reading and writing streams InputStream sin = sock.getInputStream(); BufferedReader fromServer = new BufferedReader(new InputStreamReader(sin)); OutputStream sout = sock.getOutputStream(); PrintWriter toServer = new PrintWriter (new OutputStreamWriter(sout));

6 see text pages 258-262 for more details
Full Code Examples web1.java web2.java see text pages for more details

7 Helpful String Methods
Compare two strings String name1, name2; ... if ( name1.compareTo(name2) < 0 ) Append name += " "; name = first + last;

8 Really Useful String Methods
Find a string in a larger string int firstspace = mystring.indexOf(" "); int lastspace = mystring.lastIndexOf(" "); Extracting Substrings String pre_space; pre_space=mystring.substring(0,firstspace);

9 example substring code
// program to test substrings public class string5 { public static void main (String[] args) String first,last; String bob = "bob jones"; int space = bob.indexOf (" "); System.out.println ("Space is at " + space); first = bob.substring ( 0 , space ); last = bob.substring ( space+1 ); System.out.println ("first = |" + first + "| and last = |" + last + "|"); }


Download ppt "Introduction to Client/Server Design"

Similar presentations


Ads by Google