Introduction
Table of contents
- How web clients interact with web servers - by messages!
-
- I install web servers and write CGI scripts
-
- A CGI script or SOAP server can do anything
-
- Eg they can be a database client
Substitutions:
- A web client normally means an HTML client
-
- Here,
a web client may be a SOAP client
-
- Clients talk to a web server,
CGI script or SOAP server
-
- SOAP does not have to use HTTP
- It's all about messages
-
- Protocols:
-
- DNS
-
- CGI
-
- HTML
-
- HTTP
-
- TCP/IP
-
- Modem
-
- Modem compression
At the post office:
- I'd like to buy a book of stamps,
thanx
-
- Ok,
here they are.
That'll be $5
-
- Here's $10
-
- And here's your change: $5
- First protocol is English
-
- Second protocol is Australian Currency
The customer and the server communicate via protocols.
Protocols mediate the interaction,
ie they make it work.
- It�s a browser or a non-browser
-
- HTML are commands to a browser
-
- HTML is a rendering language
-
- A browser renders content in a window according to the HTML
-
- A non-browser does not care about HTML 'v' content.
It's all data
#!/usr/bin/perl
use LWP::Simple;
print get 'http://savage.net.au/index.html';
This 3 line program is a complete, tested, web client
#!/usr/bin/perl
# Name: server-1.cgi.
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI -> dispatch_to('Demo') -> handle;
package Demo;
sub hi{return "Hello, world";}
This 6 line program is a complete, tested, SOAP server
#!/usr/bin/perl
# Name: server-1-client-1.pl.
use SOAP::Lite;
print SOAP::Lite -> proxy('http://127.0.0.1/cgi-bin/soap/server-1.cgi') -> uri('Demo') -> hi() -> result;
This 4 line program is a complete, tested, SOAP client
DOS>perl server-1-client-1.pl
Hello, world
That's all, folks!
OK, so there was no error checking. Next time!
http://savage.net.au/Ron/html/web-servers.1.png
http://savage.net.au/Ron/html/web-servers.2.png
- http://savage.net.au/index.html is a message
-
- We wish to send it from a web client to a web server
-
- savage.net.au is a domain name, ie a symbolic address
-
- How does it get converted into a numeric address, like 222.44.55.66?
-
- A Domain Name System (DNS) server converts it
- http://127.0.0.1/index.html means...
-
- the client and the server are in the same machine
-
- 127.0.0.1 is like a mirror around the PC. The message cannot leave
-
- 192.168.*.* is a mirror around a group of PCs
-
- We call this group a LAN!
-
- http://www.ietf.org/rfc/
- You can think of 127.0.0.1 as 'myself'
-
- Every person calls themselves 'myself'. Eg: I talk to myself
-
- Every TCP/IP stack calls itself 127.0.0.1
- For Win95/98/ME, see C:\Windows\hosts
-
- For WinNT/2000/XP, see C:\WinNT\system32\drivers\etc\hosts
-
- For WinNT/2000/XP, ignore C:\WinNT\hosts
-
- For Win*, ignore the sample C:\Windows\hosts.sam
-
- Explorer will lie to you, if you try to edit this file (when not logged on as Administrator)
# A hash starts a comment
127.0.0.1 ronnie.net.au
127.0.0.1 iris.ron.net.au
127.0.0.2 violet.net.au
http://ronnie.net.au/index.html is the same as http://127.0.0.1/index.html
- Client message Msg = http://savage.net.au/cgi-bin/script.cgi
-
- Each protocol encodes message
-
- CGI[Msg]
-
- HTTP{CGI[Msg]}
-
- TCP/IP(HTTP{CGI[Msg]})
-
- Modem<TCP/IP(HTTP{CGI[Msg]})>
-
- Just like Russian dolls
- The message goes to savage.net.au, ie 222.44.55.66
-
- Remember: The DNS converts savage.net.au into 222.44.55.66
-
- How do we know which program gets the message?
-
- The 'http' says it goes to an HTTP server
-
- That is, a program which volunteers to accept HTTP-type messages
-
- Default: 222.44.55.66:80
- Port 80 is the default port for HTTP
-
- What is a port?
-
- Hardware 'v' Software ports
-
- Mouse: COM1, Modem: COM2
-
- Printer: LPT1
-
- 0 .. 65535 software (logical) ports
-
- A port is the address of a server
- FTP: 23
-
- SMTP: 25 (Mail out)
-
- POP3: 110 (Mail in)
-
- A port is dedicated to a protocol
-
- Admin ports are 0 .. 1023
- A web server on port 80 can redirect
-
- Static images and pages use 127.0.0.1:8080, a small, fast server
-
- Dynamic pages use 127.0.0.1:8081, a fancy server, eg using templates
-
- Manage this via Virtual Hosts
- Message = modem<TCP/IP(HTTP{CGI[Msg]})>
-
- TCP/IP(HTTP{CGI[Msg]})
-
- HTTP{CGI[Msg]}
-
- CGI[Msg]
-
- Server message Msg = http://savage.net.au/cgi-bin/script.cgi
- The web server may handle the message (Apache):
-
- http://127.0.0.1/server-status
-
- The web server may find a real or virtual file:
-
- http://127.0.0.1/index.html
-
- The web server may run a script:
-
- http://127.0.0.1/cgi-bin/script.cgi
- http://deakin.edu.au/comp-sci/courses/scripting101.html
-
- http is a protocol (not https)
-
- deakin.edu.au is a host
-
- / is a directory
-
- comp-sci/ is a directory
-
- courses/ is a directory
-
- scripting101.html is a file
- / is the root directory of the URI
-
- / is not the root directory of the hard disk
-
- / is the root directory for that host
-
- The web server�s config file translates / into a real directory
-
- This makes the real / secure
#!/usr/bin/perl
use CGI;
my($q) = CGI -> new();
print $q -> header(),
$q -> start_html(),
$q -> start_form({action => $q -> url(), name => 'a_form'}),
'Email address: ',
$q -> textfield({name => 'email', size => 40}),
$q -> submit(),
$q -> end_form(),
$q -> end_html();
This 4 line program is a complete, tested, CGI script.
And this is the output from that CGI script, slightly simplified.
<html><head></head><body>
<form action = 'http://127.0.0.1/cgi-bin/script.cgi', name = 'a_form'>
Email address: <input type='text' name='email' size='40' />
<input type='submit'>
</form></body></html>
- The web server passes the data to the CGI script
-
- But, the very first time the CGI script runs, there is no data!
-
- So, the CGI script knows it must output a blank form this time
-
- The CGI script exits!
- When Submit is clicked:
-
- A) The data is encoded using the CGI protocol
-
- B) The message might look like:
-
- http://127.0.0.1/cgi-bin/script.cgi?email=me@here.net
-
- C) The action tells the client which server to send the message to
- It knows this is the second time the script is being run
-
- The scripts do not have to be the same
-
- But, expect to write scripts which are ALWAYS run twice
-
- Script processes the data (eg db)
-
- Script outputs a Thank You page
The lectures:
CGI scripting (lecture 2001)
Simple Document Format (lecture 2002)
Web Servers (lecture 2002)
Web Servers (*.tgz)
Web Servers (*.zip)
Ron Savage
.
Home page: http://savage.net.au/index.html
- Version: 1.01 01-Jun-2006
-
This version disguises my email address.
- Version: 1.00 13-May-2002
-
Original version.
Australian Copyright © 2002 Ron Savage. All rights reserved.
All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html