Does anyone know the how to structure a CGI-based web server application (TWebModule) so that it can issue a TCP/IP request to a separate server and wait for a response?
Here's some detail on what I would like to have happen:
1. A WebModule application is executed on web server A in response to an HTML form action.
2. This WebModule, invoked on web server A, needs to interact with another web server B to obtain data. I choose to have the WebModule pass a TCP/IP request through a TClientSocket and wait for a response from the server (using the OnRead event). The server B is running a normal Delphi application that utilizes a TServerSocket.
3. Equipped with the data from web server B, the WebModule can then complete its response to the original form action through Response (TWebResponse).
I have (1) and (3), and server B's application working fine. It is the WebModule's TClientSocket of (2) that complicates things. As I have come to learn, unlike a standard Delphi application (TApplication) which has message queue processing, TWebApplications do not. Thus, the events OnConnect, OnError, OnRead, etc. do not fire.
If I rewrite the application as a normal Delphi application (with a different user interface of course), the whole process then works fine thanks to the inherent VCL message queue processing. Unfortunately, this is not the proper form for a web server cgi executable.
I have tried a number of things including placing the communications logic to server B in a separate thread, and even trying to write my own WndProc method, but the results are always the same - no event firing. I know its possible because I see server requests routinely interact with other servers to form responses (such as W3C's HTML validation service at http://validator.w3.org/
- you provide a URL and it tells you what parts of an HMTL page do not meet the spec.)
Can someone help shed some light on this issue? BTW, I am using Delphi 5 Professional. Thank you in advance.