Wednesday, April 25, 2018
Writing Client-Server Applications in Perl: Introduction
The 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).
Obviously, this architecture has to change to accomodate changes in the way applications are used.
This is where client-server architecture comes in.
Basic Client-Server ArchitecturePerhaps 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.
In 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 different machine.
Communicating on a Client Server ApplicationAs 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.
There has to be a way of communicating between these components.
The 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 protocol.
Some ports are already used by more common applications. Webservers use port 80. Pop mail uses 110. MySQL uses 3306.
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.