Writing Client-Server Applications in Perl: Introduction
Written by Philip L Yuson
Who is this for
article is for those who would like to have an understanding of how a
client-server application works. It gives a general discussion on
traditional architecture for applications is the stand-alone
architecture. With this, all components of an application is executed
in one giant program. This is ok if the application is meant to be
used by one person on one machine at a time.
With the changes
in technology AND business processes, this architecture has to
change. We see several users now using the same application at the
same time accessing the same database(s).
architecture has to change to accomodate changes in the way
applications are used.
This is where client-server architecture
Basic Client-Server Architecture
the most common example of a client-server architecture are webpages.
The client (user on a remote location) needs to browse a page. The
client uses a browser on the PC. The browser goes to the webserver on
the site and requests the page. The webserver gets the page and sends
the page to the browser.
this case, the webserver acts does the reading and sending of the
information. Some pages are generated by CGI programs. In this case,
the webserver starts the CGI programs which generate the pages. Some
CGI programs require database access. In this case, the database can
reside on the same machine as the webserver or it can reside on a
on a Client Server Application
As we see, the application can
be split into several components. The client can perform validation
and other functions. Request is sent to the server which does the
actual processing and the result is sent back to the client.
has to be a way of communicating between these components.
most common way of communicating between components is through
sockets on each machine.
The client communicates with the server
through a predefined socket. The socket defines how communication is
handled. This defines the protocol (normally TCP), and also the port
where messages will be passed.
For ordinary web pages, the
server socket communicates through TCP on port 80. Clients requesting
web pages send messages to the server's port 80 using the TCP
Some ports are already used by more common
applications. Webservers use port 80. Pop mail uses 110. MySQL uses
If you are designing a new client-server application,
you have lots of ports to choose from. Make sure that you do not
choose any of these pre-defined ports.
Perl allows client-server applications using
the IO::Socket module. This topic will be discussed next month.