wserv_med.pl -- Webserver example, using Perl's medium level API for network access
./wserv_med.pl 2345
This is just a simple http server for CS629, Programming Assignment #3. The program takes only one argument, and that is the port number to run on. Note that only the very basics of HTTP/1.0 are implemented.
You may set the variable DOCUMENT_ROOT to the base directory of the webserver. The default is public_html in your home directory.
wserv_med.pl is written in what I consider as ``medium level API'' for network access.
Basic network calls, just as in C.
Simplified access through modules, as in Java.
Configurable HTTP Deamon, just as the Perl module HTTP::Daemon.
The following examples assumes that the webserver is run on
allegro.cs.bgsu.edu, port 2345 and that DOCUMENT_ROOT is set in the script to the path where the following index.html is in.
A form may look like this one.
The code for the form in index.html is as follows.
<html>
<head>
<title>Test</title>
</head>
<body>
Hello world!
<form method="POST" action=http://allegro.cs.bgsu.edu:2345/index.html >
<dl>
<dt>Name
<dd>First: <input type="text" name="first" value="Ron"><br>
Last: <input type="text" name="last" value="Blaschke">
</dl>
<dl>
<dt>This is a checkbox
<dd><input type="checkbox" name="check">CheckMe!
<dt>A radio group
<dd><input type="radio" name="radio" value="radio1" checked>Radio 1<br>
<input type="radio" name="radio" value="radio2">Radio 2
<dt>A single selection
<dd><select size="2" name="select-single">
<option selected>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
</select>
<dt>A multiple selection
<dd><select size="4" name="select-multiple" multiple>
<option selected>1</option>
<option selected>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</dl>
<input type="submit" name="Submit">
</form>
</body>
</html>
Make sure that the action points to the webserver address!
Now we start the webserver.
>./wserv_med 2345
Starting httpd on port 2345
Access the page http://allegro.cs.bgsu.edu:2345/index.html with a webbrowser. The webbrowser will show the form, the server will
output something like this:
1: 'GET /index.html HTTP/1.0'
2: 'Connection: Keep-Alive'
3: 'User-Agent: Mozilla/4.61 [en] (Win95; I)'
4: 'Host: allegro.cs.bgsu.edu:2345'
5: 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*'
6: 'Accept-Encoding: gzip'
7: 'Accept-Language: en'
8: 'Accept-Charset: iso-8859-1,*,utf-8'
9: ''
Enter data in the form and press ``Submit Query''. The server will output something similar to this.
1: 'POST /index.html HTTP/1.0'
2: 'Referer: http://allegro.cs.bgsu.edu:2345/index.html'
3: 'Connection: Keep-Alive'
4: 'User-Agent: Mozilla/4.61 [en] (Win95; I)'
5: 'Host: allegro.cs.bgsu.edu:2345'
6: 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*'
7: 'Accept-Encoding: gzip'
8: 'Accept-Language: en'
9: 'Accept-Charset: iso-8859-1,*,utf-8'
10: 'Content-type: application/x-www-form-urlencoded'
11: 'Content-length: 108'
12: ''
form data is:
first = 'Ron'
last = 'Blaschke'
radio = 'radio1'
select-single = 'A'
select-multiple = '1'
select-multiple = '2'
Submit = 'Submit Query'
And the webbrowser will show something like this.
Hi Ron Blaschke! Your request is processed.
Your choice was:
CheckMe! was not checked.
You selected radio 1.
You selected item A and items 1,2.
Socket, IO::Socket, HTTP::Daemon, RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1)
none known
Ronald Blaschke <rblasch@cs.bgsu.edu>
(c)1999 by Ronald Blaschke <rblasch@cs.bgsu.edu>