Penn CIT 597 - Clients and Servers (13 pages)

Previewing pages 1, 2, 3, 4 of 13 page document View the full content.
View Full Document

Clients and Servers



Previewing pages 1, 2, 3, 4 of actual document.

View the full content.
View Full Document
View Full Document

Clients and Servers

92 views

Lecture Notes


Pages:
13
School:
University of Pennsylvania
Course:
Cit 597 - Programming Languages and Techniques III.
Programming Languages and Techniques III. Documents

Unformatted text preview:

Clients and Servers Jan 14 2019 URL review A URL has the syntax protocol hostname port path anchor import java net URL url new URL String Constructs a URL object from a text string MalformedURLException This is the package that defines sockets URLs etc This exception is thrown if the given String cannot be parsed by newURL String We have used URLs to display a page in an applet appletContext showUrl URL 2 HTTP review HTTP is a protocol a formal description of a language that computers use to communicate An HTTP message consists of three parts The request or the response line A header section A request line typically contains either GET or PUT A response line contains the status code such as 404 Not Found Contains name value pairs such as Content type text html Ends with a blank line The body of the message The body is optional 3 Using a URL URLConnection c url openConnection c getHeaderField name Returns the value of the named header field as a String Frequently used fields have shorthand methods for example c getLastModified c getHeaderField last modified getHeaderField int The URLConnection is the basic way to access the resource information Returns the value of the int th header field as a String The 0 th header field is the status line c getInputStream Returns an InputStream containing the content of the resource url openStream is shorthand for url openConnection getInputStream 4 Socket review A socket is a low level software device for connecting two programs possibly on different computers together new Socket String host int port Creates a client socket and makes the connection Methods include getInputStream getOutputStream and close new ServerSocket int port Creates a server socket that listens on the specified port accept returns a Socket that can be used for I O accept is a blocking method so multithreading is highly desirable 5 How to write a server ServerSocket server new ServerSocket port Socket client server accept accept blocks while it waits for a



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Clients and Servers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Clients and Servers and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?