************************************* * * * DB/C Newsletter * * August 2002 * * * ************************************* News and Comments The dbctalk email list has been quite active recently. There have been an average of about 40 messages per week for the last few weeks. I'm still surprised that there are only about 100 subscribers to dbctalk. There are many more who read this newsletter via the dbcnews email list or at www.dbcsoftware.com. The dbctalk email list is a great resource for getting questions answered or just learning things. You don't need to post any emails - most subscribers to dbctalk are just lurkers. I've heard some say that they don't subscribe to email lists like dbctalk because they already get too much junk in their email inbox. My response is that you should subscribe to dbctalk in digest mode which accumulates a day's worth of messages into a single email message - thus you will receive one email per day. See the December 2001 DB/C Newsletter for information about how to subscribe to dbctalk. In the January 1997 DB/C Newsletter, we discussed how to use DB/C 9.0 as a CGI processing program. A CGI (Common Gateway Interface) program is a program that runs in a web server as a result of a user click on a button in an HTML form on a web page. This is the most basic method of building web applications. Unfortunately, web servers implement CGI by starting an executable program. In our case, the executable program is the DB/C DX runtime (dbc in UNIX, dbcc.exe in Windows). Because of the time required to initiate the DB/C DX 12 runtime, the CGI approach described in the January 1997 newsletter is too slow to be used in production systems. So in this month's newsletter, we discuss another approach that allows you to write your web applications with DB/C DX. Let me know if this is useful in your environment. don.wills@dbcsoftware.com ****************************************************************************** DB/C DX Web Server Program Today's web servers offer several interfaces for running applications to support web browser HTML forms processing. Unfortunately, none of these interfaces provides an optimal method for directly executing DB/C DX programs. The sample program we describe here uses a hybrid approach so that you can write your application logic in DB/C DX. The approach is to have a generic Java Servlet run on the web server. This Java program communicates with a DB/C DX program via TCP/IP. The Java Servlet is very simple. Here what it does: 1. it receives the information from the web page on which a user presses a button 2. it sends that information via TCP/IP to a waiting DB/C DX program 3. it waits for a response via TCP/IP from the DB/C DX program 4. it sends the response back to client web browser The response is HTML. It is sent back to the client web browser without any modification. Thus it is up to the DB/C DX program to create the entire web page including all formatting, images, forms, links, etc. The set of sample programs that we describe in the remainder of this article is available at www.dbcsoftware.com. Click on the Sample Code button and then download the .zip or .tar file associated with the 'DB/C DX sample web server'. You will find these files: addtest.html HTML that is the first page of the application addtest.java the Java Servlet addtest.prg the DB/C DX program that does the addtest processing The function of the sample application is to add two numbers together and return the result. The first number is entered on the first web page. The second number is entered on the second web page. The result is then displayed in the third web page. The sample application starts when the user links to the addtest.html page. This web page is titled 'Page 1'. It consists of one data entry field titled 'Enter value 1' and a button labeled 'submit'. When the 'submit' button is pressed, the Java Servlet (addtest.java) receives a POST message from the web server. The Java Servlet recognizes that this POST message is not the continuation of a previous session so it assigns a new session id. It then sends the session id and all of the other information from the POST message to the DB/C DX program (addtest.prg). When addtest.prg receives the message, it recognizes that the message is for a new session and that it is a valid 'Page 1' message. It saves the session id and the value from page 1. It then creates the entire 'Page 2' HTML and sends it back to addtest.java along with the session id. When the addtest.java program receives the HTML back from the DB/C DX program, it forwards it the the web server which sends it to the web browser. In our sample, the page 2 that is being sent is basically the same as page 1, except that it says 'Enter value 2'. When the user enters a value and presses the submit button on page 2, the whole process repeats again except that the Java Servlet recognizes that this is a continuation of a session. As a result, it sends the same session id to the DB/C DX program as was sent for page 1. The DB/C DX program then recognizes that it is an existing session and retrieves the first value stored, adds it to value 2, and then formats a page 3 which displays the sum of the two values. In addition, when the DB/C DX program sends back the page 3 HTML, it sends a blank session id. This is an indication to the Java Servlet that the session is terminated. In response, the Java Servlet disposes of that session id and the session is finished after the page 3 HTML is sent to the web browser. The addtest.prg DB/C DX program is designed to handle up to fifty concurrent sessions and to have three TCP/IP connections waiting for receipt of messages from one or more Java Servlets. In high performance web servers, Java Servlets are usually configured to be multithreaded, thus it is possible for two users to press the submit buttons almost simultaneously which will cause two threads of the Java Servlet to attempt to connect to the DB/C DX program almost simultaneously. By having multiple connections waiting in addtest.prg, both Java Servlets will connect successfully even though they will be handled sequentially in the single threaded DB/C DX program. A simpler approach would be for the DB/C DX program to have only one connection available. However, in this case, the second Java Servlet would encounter an error trying to connect and it would have to wait a few seconds and try again. This would cause erratic performance in a high volume environment. If you have any questions about these programs or this approach, I suggest that you send them to the dbctalk email list. ****************************************************************************** DB/C DX Class Schedule Class: DB/C DX Fundamentals Date: September 16-18, 2002 Location: Oak Brook, Illinois For information, send email to admin@dbcsoftware.com. ****************************************************************************** Subscribing to the DB/C Newsletter If you don't already have the DB/C Newsletter delivered to your email address and would like to have it emailed to you monthly, just send an email message to 'dbcnews-subscribe@dbcsoftware.com'. The newsletter will be delivered to the email address from which the message was sent.