Introduction

Table of contents

Introduction
Web Clients and Servers
Topics of Discussion
What is a Protocol?
What is a Web Client?
A real, live, Web Client
A real, live, SOAP Server
A real, live, SOAP Client
Output from that SOAP Client
Running a Script
The Request Loop
Finding the Destination
Special Destinations
127.0.0.1
DNS under MS Windows
The hosts file
Encoding the Message
Finding the Server
What is port 80?
Other Ports
Load Balancing
Decoding the Message
Processing the Message
Processing a URI
/ is a directory
A CGI script
Output from a CGI Script
Why output that form?
Interpretation
When the CGI script gets data
Resources
Author
Licence

Introduction

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

Web Clients and Servers

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

Topics of Discussion

It's all about messages
Protocols:
DNS
CGI
HTML
HTTP
TCP/IP
Modem
Modem compression

What is a Protocol?

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.

What is a Web Client?

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

A real, live, Web Client

        #!/usr/bin/perl
        use LWP::Simple;
        print get 'http://savage.net.au/index.html';

This 3 line program is a complete, tested, web client

A real, live, SOAP Server

        #!/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

A real, live, SOAP Client

        #!/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

Output from that SOAP Client

        DOS>perl server-1-client-1.pl
        Hello, world

That's all, folks!

OK, so there was no error checking. Next time!

Running a Script

http://savage.net.au/Ron/html/web-servers.1.png

The Request Loop

http://savage.net.au/Ron/html/web-servers.2.png

Finding the Destination

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

Special Destinations

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/

127.0.0.1

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

DNS under MS Windows

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)

The hosts file

        # 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

Encoding the Message

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

Finding the Server

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

What is port 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

Other Ports

FTP: 23
SMTP: 25 (Mail out)
POP3: 110 (Mail in)
A port is dedicated to a protocol
Admin ports are 0 .. 1023

Load Balancing

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

Decoding the Message

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

Processing the Message

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

Processing a URI

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 a directory

/ 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

A CGI script

        #!/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.

Output from a 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>

Why output that form?

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!

Interpretation

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

When the CGI script gets data

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

Resources

The lectures:

CGI scripting (lecture 2001)

Simple Document Format (lecture 2002)

Web Servers (lecture 2002)

Web Servers (*.tgz)

Web Servers (*.zip)

Author

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.

Licence

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