Web Server Programs
Introducing World Wide Web Server Programming
SIMPOL's earliest interactive program capabilities were as a web server application. This was done because it was the easiest way to build programs that were able to interact with the user, since we didn't need to worry about building user interface components. As part of the implementation, we decided to support the CGI standard, ISAPI (Microsoft's proprietary interface for IIS) and something called Fast-CGI, which is a high-performance version of CGI that can handle larger loads. It does this by allowing the program code to remain loaded for a certain amount of time, so that subsequent calls to the same program do not need to also go through initialization.
There are typically two approaches to web application programming, page-centered and program-centred. Examples of page-centered programming are typically found in PHP and ASP programs. The page is the focus of the development. This works well for people who are mainly graphics designers and who want to add a little bit of code to their pages. The other approach tends to be much more about the application code, which will, based on the current state, display any of a number of pages. Both are valid methods of working, though application programmers may find the page-centric approach difficult to follow.
SIMPOL supports to some degree both styles. The IDE has support for a file format called
*.smz which is a form of HTML with embedded SIMPOL code. During the compilation phase these files are converted to program code with embedded HTML. In the standard versions used in ASP and PHP, these pages are processed by the server when they are requested, whereas in SIMPOL they are already compiled to byte code.
The hardest part about web server programming is debugging something like this, which runs in the server, since you can't control the execution. We solved this problem way back in 2003, by building a special program to act as the loader for the CGI program, and which then connects to the SIMPOL IDE to debug the program. This works extremely well and makes debugging the program quite easy. This loader program is called
Styles of Web Server Application
There are a number of differences between the different web server loading methods. Both the CGI and ISAPI approaches use a
main() function that takes a
cgicall cgi parameter. The main difference between the two is what the current directory is. For CGI programs, the current directory is the same as the location of the program that is being loaded, while for ISAPI programs, they normally start in the %SYS32 directory.
The Fast-CGI program is quite different to the other two, though like with CGI, the location of the program file is also the location of the current directory. Instead of a
main(), there are three separate functions. They are:
fcgiinit(), which takes no parameters,
fcgi(), which takes a cgicall cgi parameter, and an optional
type(*) <paramname> parameter, which is the return value from the
fcgiinit() function. Finally, there is an
fcgiterm() function that takes the return value from the
fcgiinit() function to allow any required clean up to take place. One example of this might be if a dynamically loaded library is opened during initialization and in that some memory is reserved. Then during the clean up phase that memory could be released. In most SIMPOL web server programs, there will be little need for the final function, except as an empty function so that it can be called although it will do nothing.
Valuable Reading References Within the SIMPOL Documentation
The SIMPOL IDE Users Guide contains a section in Chapter 3, The SIMPOL Project, dedicated to what is called “SIMPOL Server Pages”. This fairly extensive section discusses the various aspects of working with the IDE and web server applications.
In the SIMPOL IDE Quick Start Manual, in Chapter 3 Writing Web Server Programs With SIMPOL, a complete example of writing a web server program is presented, including setting up the Apache web server and debugging the application. This is well worth a read.
Sample Web Server Applications Shipped with SIMPOL
\SIMPOL\Projects\ssp directory contains a group of sample programs that demonstrate how to create and run applications from the web server. These include samples that are interlinked in some cases. It also includes both database and non-database related programs. The sbiscalendar project produces a simple calendar. The current day of the month is highlighted in a different color. There is also a useful tool for examining the environment variables that are available to the program- ming environment, called
sbisenvvars. The following demonstrate basic database usage:
The starting point is the first item. To try it out at
http://www.simpol.com/cgi-bin/sbiscontact.smp. These can all be set up to run on a local web server running on your development computer. The easiest approach is to install a local copy of the Apache web server. Then you will need to modify the local target in each project to match your system architecture. If the installer was able to find apache, it may have already modified the programs. The programs look for the
sbis.ini file, so that may need to be modified, as will the
basehref in the
header.htm file. All of the items that are needed for the web server can be found in the apache inside of the ssp directory. It is a good idea to also run a local PPCS server to host the database. The samples ship with everything required in the ppcsserver directory in the project folder.
Finally there is a frame sample, which is admittedly someone outdated in terms of modern web design, but still may have some use. To run it, start the
sbisframesample.smp in your browser using the correct URL or try it at
The Web Server "Sandwich" Method
Many web server applications can be seen as the filling inside of a web page. The part of the web page that precedes the place in the content where the output of the program is placed is the top piece of bread, and the part that follows the content is the bottom piece of bread. In some cases it may be necessary to have 3 chunks of HTML that represent the page, the top part, from the initial HTML declaration down to the place in the header where the
basehref is inserted, then the remainder of the header plus the start of the body, and finally the remainder of the body and the footer. In SIMPOL we use this approach quite heavily. A program can be made to look like a part of any target system by taking a typical page from that system, dividing it into the necessary chunks, and then using the
SBISInclude() function to read those chunks of HTML from the storage media when the program is run on the web server. It is fast and efficient.
Web Server Application Summary
In this chapter we have discussed the development of web server applications using SIMPOL. We haven't gone into detail about how to actually program these, since the mechanics of programming a web server application are covered in two other places in the SIMPOL documentation, and a group of sample programs demonstrating various aspects of web server application programming are included with the sample projects. This is just the beginning of a journey. Web server programming is a large an growing topic, but by using this facility within SIMPOL you can feel confident that you can deploy web server applications that use databases stored in your system and that may even be used by desktop program in-house. We use this sort of approach ourselves, with a basic web system for use by our customers and an expanded desktop system written in SIMPOL for in-house use.
The tools are there, where you want to take it, is really up to you!