CSc31800 Internet Programming

Spring 2004, CCNY-CUNY, Jinzhong Niu

Things you may need to know regarding project work:

1. JDK and Its Documentation

If you want to set up an Java environment on your own computer, simply go to, where you can find links for J2SE(Java2 Standard Edition, the most common JDK distribution) v 1.4.2_03 installation programs and documentation package.

Depending upon which platform you are using, you may either download J2SE v 1.4.2 for Windows, Linux, or Solaris. Whichever package you obtain is executable on its corresponding platform, so simply run it to install.

The documentation package is a ZIP file, which you may uncompress to the installation directory of J2SE. After you do so, you will find all the document files reside in the docs subdirectory. The index.html file in docs/api/ subdirectory is the main page for Java Library API, where you can check the definition and usage of any Java class. If you are unwilling to have a local copy of this documentation but always have an Internet connection available, you may easily access the online version of the documentation by googling "JDK DOC" since it comes first in the results.

2. Protocol Implementation

You have to be extremely cautious when implementing a network protocol since even one byte of data violating the specification will lead to a system-wide failure. For instance, since it is required to use CRLF to indicate the end of each line in request or response messages, you must add those two chars, both '\r' and '\n', to complete one line before it is sent out. For another instance, since a blank line is needed to separate the possible header lines and the optional message body, you must put "\r\n" at the very location. So though the specifications of network protocols seem kind of theoretical to some people at first glance, later on they may turn out to be extremely technical and thorough as something the programmers have to seek help from and cooperate with.

In the case of HTTP, you are strongly recommended to read HTTP/1.1 Specification (RFC2616) for detailed definition of HTTP behaviors.

3. Default Starting Web Page of Web Servers

In Project #2, your client is supposed to send HTTP requests to a web server. If only the address of the web server is given in the command line without any explicit file name, then simply send the following request:
 GET / HTTP/1.0\r\n
 GET / HTTP/1.1\r\n
 Host: <server address>\r\n

Some people have used '/index.html' in the first line instead of '/', which led to bad-request responses from some servers. The reason why '/index.html' is problematic is that each web site has a default starting web page, which is used whenever the client gives the path '/' without specifying a file name explicitly. Some websites DO use 'index.html' as the default starting web page, so '/index.html' really exists. That is why your client DOES work with some websites. However some other websites may use a different name for this purpose, in this case, '/index.html' cannot be found. So avoid using any default file name when no file is specified on the client side. And remember to have this capability in your server in Project #3, i.e. mapping '/' to '/default.html'.

4. Java URL Class

Note that Java Library have included several classes to deal with URLs, including HTTP-scheme URLs, which means that Java Library have got at least part of HTTP protocol implemented. Since our goal of this course is to learn how to develop Internet applications, you are supposed to develop from scratch or a lower level. In the case of HTTP, our base is socket mechanism. You have to use Socket and ServerSocket to fulfill your task rather than directly use URL or URLConnection classes. Don't mention HttpURLConnection.

© Jinzhong Niu, 2004