CS 455/555 - Intro to Networks and Communications
Fall 2008: Tues/Thurs 3-4:15pm, Dragas 1117

Print - Admin

Announcements

Staff

Schedule

Syllabus (pdf)

Useful Links

Program 1: URL Parser

Assigned: Thursday, August 28, 2008
Due: Tuesday, September 9, 2008 before class

Description Background Requirements Rules Testing Submission Java Intro

Description

During the semester, we will be building up to writing a text-based web client that can request and download a single file from a web server using HTTP, which is the protocol used by two computers to exchange information on the web. This first assignment will not involve any networking or socket programming, but will just get you started on the way to building an HTTP client in Java on the CS Unix systems.

Note: Do not wait until the last minute to start this assignment. If you are inexperienced with Java or Unix, please look at the tutorials posted on the course webpage and ask questions early.

Background

Your program will take a URL as its only command-line argument. The URL will be given in the following format:
http://hostname[:port][/path]

hostname - the web server's hostname

:port - an optional command that tells the web client to connect to a different port than the default of port 80 (we'll talk more about how this is used later on)

path - the path from the web server's main directory to the requested file, if this is not present, then the path is '/'

URL Examples:

http://www.cs.odu.edu/~mweigle/CS455-F08

http://www.fakehost.com:765/fakepath/fakefile.html

The hostname is shown in bold font, and everything after the first '/' following the hostname is part of the path.

Requirements

  • Take a URL as the only command-line argument. If given no command-line argument, print a "Usage" statement and exit.
  • If the URL does not start with "http://", print an error message and exit.
  • Separately print the URL, hostname, port (80, if no alternate port is given), and path provided in the URL.
  • Your program should not crash, no matter the input given to it.

Rules

  • As with all projects, you are not permitted to work with anyone else (even students not in the class) - all of the coding and documentation must be your own.
  • Your program must compile and run on the CS Unix machines. If you do not have an account, see me today!

Testing

Your program will be graded on how well it satisfies the requirements in handling a set of test URLs. You should test your program rigorously with various URLs before submitting.

Example 1

% java UrlParser http://www.cs.odu.edu/~mweigle/foo.txt

URL : http://www.cs.odu.edu/~mweigle/foo.txt 
Host: www.cs.odu.edu 
Port: 80 
Path: /~mweigle/foo.txt

Example 2

% java UrlParser http://www.amazon.com:4567/Harry_Potter/this/is/a/book.html

URL : http://www.amazon.com:4567/Harry_Potter/this/is/a/book.html 
Host: www.amazon.com 
Port: 4567 
Path: /Harry_Potter/this/is/a/book.html

Example 3

% java UrlParser http://www.amazon.com 

URL : http://www.amazon.com 
Host: www.amazon.com 
Port: 80 
Path: /

Example 4

% java UrlParser http://www.amazon.com/ 

URL : http://www.amazon.com/ 
Host: www.amazon.com 
Port: 80 
Path: /

Example 5

% java UrlParser

Usage: java UrlParser URL

Submission

You must name your source file UrlParser.java. Make sure that you submit all files necessary to compile your program. But, do not submit compiled files (.class files).

Directions for submitting your assignment through Blackboard

Getting Started with Java

If you've never programmed with Java before, here are a couple of helpful hints:

  • Java syntax is very, very similar to C++.
  • Only one class is allowed per file, and the name of the class must match (exactly!) the name of the file. For Program 1, you are to name your source file UrlParser.java, so you must name your class UrlParser.
  • The "import" statement is used give access to built-in libraries, much like the "#include" statement in C/C++.
  • To print output (instead of printf), use System.out.print() or System.out.println(). println() adds a newline character to the end of the String given.
  • The main method should be declared as "public static void main (String argv[])". The String array, argv, gives you access to the command-line arguments. The first element of the array (argv[0]) is the first argument (and not the program name as in C/C++).
  • To compile your program, use "javac". Ex: javac UrlParser.java
  • To run your program, use "java". Ex: java UrlParser http://www.amazon.com
  • The Java String class reference will be useful in completing this assignment.

Here is the skeleton for Program 1 (to be saved as UrlParser.java):

// Insert Your Name 
// Insert Your Class (CS 455 or CS 555), Fall 2008
// Program 1 - URL Parser 

import java.io.*; 

class UrlParser { 

   public static void main (String argv[]) 
   { 

       // insert your code here 

   } 
}