There are four+ phases in the development process:
See the MyWebServer Tips file for some suggestions once you get coding.
That is, if the client sends the message, "ABC Hello there in Server land!
You now have a simple "listener" program which echos all input on the server
console .
If you want to be fancy, your MyListener program can, in addition to the
console display, also send all of the information back to the client as
HTML-formatted data. This is not required, and note that you will have to
send back the corrent MIME type for HMTL: "Content-Type: text/html [cr/lf]
[cr/lf]" (see below).
You will connect at port 80 instead of the default telnet port of 23,
because you want to talk to the web server, instead of the telnet server.
Do this by entering the shell command,
Hint: some of the information, such as the "Accept" and "User-Information"
info is not needed by the web server, and you can find this through
experimentation.
C:\dp\420\java>java MyListener
Clark Elliott's Port listener running at 2566.
GET /~elliott/dog.txt HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
Host: localhost:2566
Connection: Keep-Alive
(Note: you may wish to experiment with "Connection: close" with your
webserver if you are having buffering problems.)
telnet students.depaul.edu 80
The shrike web server is now waiting for input from you.
students> script
students> telnet condor.depaul.edu 80
GET /~elliott/dog.txt HTTP/1.1
Host: condor.depaul.edu:80
[Elliott note: two carriage return / linefeeds (crlfs) go here.]
and we get back the response something like the following:
HTTP/1.1 200 OK
Date: Fri, 16 Sep 2005 18:09:38 GMT
Server: Apache/2.0.53 HP-UX_Apache-based_Web_Server (Unix) PHP/4.3.8
Last-Modified: Fri, 16 Sep 2005 18:08:50 GMT
ETag: "5e1c1-2f-7c517080"
Accept-Ranges: bytes
Content-Length: 47
Content-Type: text/plain
This is Elliott's dog file on condor and hawk.
Connection closed by foreign host.
students>[control-d] [your session is stored in a file called typescript]
HTTP/1.1 200 OK Content-Length: 47 [Where 47 is changed to the real length of the data -- but note that you might make initial tests by just setting this value high] Content-Type: text/plain [Where text/plain might also be: text/html, text/vnd.wap.wml] [followed by two carriage return / linefeeds (crlf), and then the data.] The following end of line hints might be useful:static final byte[] EOL = {(byte) '\r', (byte) '\n'}; or: outstream.writeBytes("Content-Type: " + ConType + "\r\n\r\n"); or: outstream.print("\r\n\r\n");
[...] <h1>Index of /~elliott/420/.xyz</h1> <pre><img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O=D">Name</a> <a href="?C=M;O=A">Last modified</a> <a href="?C=S;O=A">Size</a> <a href="?C=D;O=A">Description</a><hr><img src="/icons/back.gif" alt="[DIR]"> <a href="/~elliott/420/">Parent Directory</a> - <img src="/icons/text.gif" alt="[TXT]"> <a href="first-file.txt">first-file.txt</a> 16-Sep-2005 14:09 39 <img src="/icons/text.gif" alt="[TXT]"> <a href="second-file.html">second-file.html</a> 16-Sep-2005 14:09 67 <img src="/icons/text.gif" alt="[TXT]"> <a href="third-file.wml">third-file.wml</a> 16-Sep-2005 14:09 222 <img src="/icons/folder.gif" alt="[DIR]"> <a href="z-directory/">z-directory/</a> 16-Sep-2005 15:08 - </pre>Which displays as:
We can simplify this as follows:Index of /~elliott/420/.xyz
Name Last modified Size Description
Parent Directory -
first-file.txt 16-Sep-2005 14:09 39
second-file.html 16-Sep-2005 14:09 67
third-file.wml 16-Sep-2005 14:09 222
z-directory/ 16-Sep-2005 15:08 -
<pre> <h1>Index of /~elliott/420/.xyz</h1> <a href="/~elliott/420/">Parent Directory</a> <br> <a href="first-file.txt">first-file.txt</a> <br> <a href="second-file.html">second-file.html </a><br> <a href="third-file.wml">third-file.wml</a><br> <a href="z-directory/">z-directory/</a><br>Which displays as:
Index of /~elliott/420/.xyz
Parent Directory
first-file.txt
second-file.html
third-file.wml
z-directory
For those who are more ambitious, here is a starting link on java's JNI, which allows us to call native code, by loading it into the virtual machine, and then running it. Sun JNI example. In this way we might write programs that actually run arbitrary scripts/programs under the web server.
Alternatively, for those writing in C, the "system()" function will execute any executables as subprocesses, making the running of programs and scripts trival. Note: be very security conscious of running user-input shell commands with the "system()" call, because, e.g., they might have you execute a command to erase all of your files!
Neither method is required. Instead, to keep the programming scope reasonable, we will only simulate the running of back-end scripts. CGI (the Common Gateway Interface) has been around since the beginning of the web, so there are thousands of references on how to use it such as these CGI notes which seem to date from about seven years ago.
<FORM METHOD="GET" ACTION="http://localhost:2566/cgi/addnums.fake-cgi">...which would suggest that you have a script in the /cgi subdirectory of your server, named addnums.fake-cgi that will handle the input from the current HTML form.
GET /cgi/addnums.fake-cgi?person=Matilda&num1=4&num2=5 HTTP/1.1