Introduction to Client/Server Design - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Client/Server Design

Description:

CSCI 392 Java Programming ... Client Code // connect to the server Socket sock ... web1.java web2.java see text pages 258-262 for more details ... – PowerPoint PPT presentation

Number of Views:148
Avg rating:3.0/5.0
Slides: 10
Provided by: Stephe774
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Client/Server Design


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
  • GET /path/file HTTP/1.0
  • misc headers
  • blank line
  • Reply Message
  • HTTP/1.1 200 OK
  • Content-Length 3731
  • Content-Type text/html
  • Last-Modified Tue, 16 Aug 2011 211001 GMT
  • Accept-Ranges bytes
  • ETag "6178b5dc585ccc11819e"
  • Server Microsoft-IIS/6.0
  • MicrosoftOfficeWebServer 5.0_Pub
  • X-Powered-By ASP.NET
  • Connection close
  • lthtmlgt
  • ltheadgt
  • lttitlegtSteve Dannellylt/titlegt

5
Sample Client Code
  • // connect to the server
  • Socket sock new Socket ("faculty.winthrop.edu",8
    0)
  • // 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
Full Code Examples
  • web1.java
  • web2.java
  • see text pages 258-262 for more details

7
Helpful String Methods
  • Compare two strings
  • String name1, name2
  • ...
  • if ( name1.compareTo(name2) lt 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_spacemystring.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 ( space1 )
  • System.out.println ("first " first "
    and
  • last " last
    "")
Write a Comment
User Comments (0)
About PowerShow.com