Board index » delphi » Building a web server.

Building a web server.

I'm trying to implement support for CGI applications on a web server that
I'm writing.

I was wondering if anyone has an example of how to call a CGI.exe that's
been written with Delphi.

Thanks in advance

Colin.

 

Re:Building a web server.


Quote
Colin Dawson wrote in message ...
>I'm trying to implement support for CGI applications on a web server that
>I'm writing.

>I was wondering if anyone has an example of how to call a CGI.exe that's
>been written with Delphi.

This really a function of the CGI spec, not of Delphi executables.

IIANM, and you should definitely not take my word for it,
the headers (and some standard values) are made available
through the environment, and the body appears on stdin.

Groetjes,
Maarten Wiltink

Re:Building a web server.


Quote
"Maarten Wiltink" <maar...@kittensandcats.net> wrote in message

news:9vcmkk$amk$1@news1.xs4all.nl...
Quote
> Colin Dawson wrote in message ...
> >I'm trying to implement support for CGI applications on a web server that
> >I'm writing.

> >I was wondering if anyone has an example of how to call a CGI.exe that's
> >been written with Delphi.

> This really a function of the CGI spec, not of Delphi executables.

> IIANM, and you should definitely not take my word for it,
> the headers (and some standard values) are made available
> through the environment, and the body appears on stdin.

> Groetjes,
> Maarten Wiltink

This is exactly what I'm looking for. How can I find and implement the CGI
spec?

Don't forget, I'm writing a web server and want to call web apps.

Regards

Colin.

Re:Building a web server.


Quote
Colin Dawson wrote in message ...
>"Maarten Wiltink" <maar...@kittensandcats.net> wrote in message
>news:9vcmkk$amk$1@news1.xs4all.nl...
>> Colin Dawson wrote in message ...
>> >I'm trying to implement support for CGI applications on a web server
that
>> >I'm writing.

>> >I was wondering if anyone has an example of how to call a CGI.exe
that's
>> >been written with Delphi.

>> This really a function of the CGI spec, not of Delphi executables.

>> IIANM, and you should definitely not take my word for it,
>> the headers (and some standard values) are made available
>> through the environment, and the body appears on stdin.

>> Groetjes,
>> Maarten Wiltink

>This is exactly what I'm looking for. How can I find and implement the CGI
>spec?

Frankly, I don't know. I kind of figured it out from what the
web server I experimented with appeared to do.

Groetjes,
Maarten Wiltink

Re:Building a web server.


Quote
> I'm trying to implement support for CGI applications on a web server that
> I'm writing.

> I was wondering if anyone has an example of how to call a CGI.exe that's
> been written with Delphi.

> Thanks in advance

> Colin.

I'm trying to develop a web server, not a CGI App.    I've found the CGI
Spec, and I'm started to ready through it.

You'll find it at..... http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

I'm trying to write a program that will call the CGI programs.    My web
SERVER is written using Delphi 5, I kinda, think that I need to call the
CreateProcess API. But I don't know how the send the stdin information
that's needed, and then grab the stdout information that's normally shown on
screen.  If anyone can help with this part I'd be very greatful.

Regards

Colin Dawson.

Re:Building a web server.


Kicking off an EXE then pumping data in via the StdIn and getting the
response via StdOut is only one way of skinning a cat.

Given that you have written a Webserver, you might think about
communicating directly with the Apps - this CGI stuff is simply a
protocol for people to write bolt ons for other people's Webservers.

The whole idea of kicking off an EXE, letting it crank itself up, do a
bit of work and then shut itself down strikes me as wasteful in the
extreme.

However to do it you need to use :

      CreatePipe
      CreateProcess
      WriteFile
      WaitForSingleObject
      GetExitCodeProcess
      ReadFile
      CloseHandle

If you are trying to add full functionality to your Webserver then you
might also take a look at O'Reilly's CGI-WIN specification which
basically uses INI files

On Fri, 14 Dec 2001 12:38:57 -0000, "Colin Dawson"

Quote
<N...@cdawson.tele2.co.uk> wrote:
>> I'm trying to implement support for CGI applications on a web server that
>> I'm writing.

>> I was wondering if anyone has an example of how to call a CGI.exe that's
>> been written with Delphi.

>> Thanks in advance

>> Colin.

>I'm trying to develop a web server, not a CGI App.    I've found the CGI
>Spec, and I'm started to ready through it.

>You'll find it at..... http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

>I'm trying to write a program that will call the CGI programs.    My web
>SERVER is written using Delphi 5, I kinda, think that I need to call the
>CreateProcess API. But I don't know how the send the stdin information
>that's needed, and then grab the stdout information that's normally shown on
>screen.  If anyone can help with this part I'd be very greatful.

>Regards

>Colin Dawson.

Re:Building a web server.


Quote
Colin Dawson wrote in message ...
>> I'm trying to implement support for CGI applications on a web server
that
>> I'm writing.

>> I was wondering if anyone has an example of how to call a CGI.exe that's
>> been written with Delphi.

>> Thanks in advance

>> Colin.

>I'm trying to develop a web server, not a CGI App.    I've found the CGI
>Spec, and I'm started to ready through it.

>You'll find it at..... http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

>I'm trying to write a program that will call the CGI programs.    My web
>SERVER is written using Delphi 5, I kinda, think that I need to call the
>CreateProcess API. But I don't know how the send the stdin information
>that's needed, and then grab the stdout information that's normally shown
on
>screen.  If anyone can help with this part I'd be very greatful.

Yes Colin, I got your point. You're building a SERVER. I guessed
how a SERVER is expected to work from the way another SERVER reacted
to a CGI request. So in my case it was to build a CLIENT... I was
trying to find out the INTERFACE.

CreateProcess lets you specify a StartupInfo struct (I think it was)
and there you can set flags that enable fields where you can specify
handles for stdin, stdout, and stderr. Read the help file one click
further. Pipes are great if you can use them, but it appears they're
implemented in NT only and not in Win9X.

Groetjes,
Maarten Wiltink

Re:Building a web server.


ah, I see.

I'll have a go at trying to implement this over the weekend.  I was actually
thinking of implementing my own coding methods too, but as I wanted to keep
the server quite simple, I thought support   HTML, CGI possibly ISAPI and my
own format would be easiest.

I'll let you know how I get on.

Thanks for the pointer.

Colin.

Quote
"J French" <je...@iss.u-net.com> wrote in message

news:3c19fab6.14033520@news.u-net.com...
Quote
> Kicking off an EXE then pumping data in via the StdIn and getting the
> response via StdOut is only one way of skinning a cat.

> Given that you have written a Webserver, you might think about
> communicating directly with the Apps - this CGI stuff is simply a
> protocol for people to write bolt ons for other people's Webservers.

> The whole idea of kicking off an EXE, letting it crank itself up, do a
> bit of work and then shut itself down strikes me as wasteful in the
> extreme.

> However to do it you need to use :

>       CreatePipe
>       CreateProcess
>       WriteFile
>       WaitForSingleObject
>       GetExitCodeProcess
>       ReadFile
>       CloseHandle

> If you are trying to add full functionality to your Webserver then you
> might also take a look at O'Reilly's CGI-WIN specification which
> basically uses INI files

> On Fri, 14 Dec 2001 12:38:57 -0000, "Colin Dawson"
> <N...@cdawson.tele2.co.uk> wrote:

> >> I'm trying to implement support for CGI applications on a web server
that
> >> I'm writing.

> >> I was wondering if anyone has an example of how to call a CGI.exe
that's
> >> been written with Delphi.

> >> Thanks in advance

> >> Colin.

> >I'm trying to develop a web server, not a CGI App.    I've found the CGI
> >Spec, and I'm started to ready through it.

> >You'll find it at..... http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

> >I'm trying to write a program that will call the CGI programs.    My web
> >SERVER is written using Delphi 5, I kinda, think that I need to call the
> >CreateProcess API. But I don't know how the send the stdin information
> >that's needed, and then grab the stdout information that's normally shown
on
> >screen.  If anyone can help with this part I'd be very greatful.

> >Regards

> >Colin Dawson.

Re:Building a web server.


IMO CGI is a waste of space - unless one is writing to a spec.

Any half decent Webserver is going to be up, alive and waiting for
requests from the HTML 'processor'.  

Bear in mind that extended GETs and pretty well all POSTs are
extensions to HTML - HTML is a filing system - all the other stuff
just produces a 'virtual' filing system.

The word 'delegation' comes to mind.

I shall be curious to hear what you come up with - my last excursion
in this field was interesting - a technical triumph - but financially
I got stitched up.

IMO have a separate App that runs CGI - PostMessage will avoid
problems - and ... unless it is in the spec ... avoid spawning.

On Fri, 14 Dec 2001 14:49:34 -0000, "Colin Dawson"

Quote
<n...@cdawson.tele2.co.uk> wrote:
>ah, I see.

>I'll have a go at trying to implement this over the weekend.  I was actually
>thinking of implementing my own coding methods too, but as I wanted to keep
>the server quite simple, I thought support   HTML, CGI possibly ISAPI and my
>own format would be easiest.

>I'll let you know how I get on.

>Thanks for the pointer.

>Colin.

>"J French" <je...@iss.u-net.com> wrote in message
>news:3c19fab6.14033520@news.u-net.com...
>> Kicking off an EXE then pumping data in via the StdIn and getting the
>> response via StdOut is only one way of skinning a cat.

>> Given that you have written a Webserver, you might think about
>> communicating directly with the Apps - this CGI stuff is simply a
>> protocol for people to write bolt ons for other people's Webservers.

>> The whole idea of kicking off an EXE, letting it crank itself up, do a
>> bit of work and then shut itself down strikes me as wasteful in the
>> extreme.

>> However to do it you need to use :

>>       CreatePipe
>>       CreateProcess
>>       WriteFile
>>       WaitForSingleObject
>>       GetExitCodeProcess
>>       ReadFile
>>       CloseHandle

>> If you are trying to add full functionality to your Webserver then you
>> might also take a look at O'Reilly's CGI-WIN specification which
>> basically uses INI files

>> On Fri, 14 Dec 2001 12:38:57 -0000, "Colin Dawson"
>> <N...@cdawson.tele2.co.uk> wrote:

>> >> I'm trying to implement support for CGI applications on a web server
>that
>> >> I'm writing.

>> >> I was wondering if anyone has an example of how to call a CGI.exe
>that's
>> >> been written with Delphi.

>> >> Thanks in advance

>> >> Colin.

>> >I'm trying to develop a web server, not a CGI App.    I've found the CGI
>> >Spec, and I'm started to ready through it.

>> >You'll find it at..... http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

>> >I'm trying to write a program that will call the CGI programs.    My web
>> >SERVER is written using Delphi 5, I kinda, think that I need to call the
>> >CreateProcess API. But I don't know how the send the stdin information
>> >that's needed, and then grab the stdout information that's normally shown
>on
>> >screen.  If anyone can help with this part I'd be very greatful.

>> >Regards

>> >Colin Dawson.

Re:Building a web server.


Usually, people simply pick up a server like (open-source) Apache and
use Delphi to create modules to go with it .. or services that those
modules can connect-to and use.

For instance, I once consulted for a company that uses Apache to drive
the web-site; PHP4 to drive the pages; and Delphi to implement a
service-process that brokers the various database (and other) requests
that need to be delivered to a variety of different legacy corporate
systems -- depending on the type of request being made.

A similar process could be build using ISAPI of course but that requires
using (yeech!) Microsoft IIS as the server.

In any case, the program you're using is not usually created as an EXE,
as in the old traditional "cgi" model, even though the moniker "cgi"
often sticks.  It's much more efficient to do it as a DLL, as a Unix
loadable-module, and so on.  Loading and unloading of programs is an
expensive, usually-serialized procedure on most operating systems; Win32
(and Linux) are no exceptions.  [Although Win32 at least does use "lazy"
memory-cleanup so that, if you run the same program twice in a row in a
short period of time, you do not incur the full expense of reloading it
the second time.

Quote
>Colin Dawson wrote:

> I'm trying to implement support for CGI applications on a web server that
> I'm writing.

> I was wondering if anyone has an example of how to call a CGI.exe that's
> been written with Delphi.

> Thanks in advance

----------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259
mailto:i...@sundialservices.com  (PGP public key available.)
Quote
> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  Release 4.0 is here!!
> http://www.sundialservices.com/products/chimneysweep

Re:Building a web server.


Quote
> IMO CGI is a waste of space - unless one is writing to a spec.

Got it in one, I'm writing to a spec. And why yes it is literally a waste of
space, it loads a whole new exe for every single call!

Quote
> Any half decent Webserver is going to be up, alive and waiting for
> requests from the HTML 'processor'.

Yep, got that much done already.

Quote
> Bear in mind that extended GETs and pretty well all POSTs are
> extensions to HTML - HTML is a filing system - all the other stuff
> just produces a 'virtual' filing system.

I know that. I'm trying to put those extentions in place.

Quote
> The word 'delegation' comes to mind.

Guess who got delegated too!

Quote
> I shall be curious to hear what you come up with - my last excursion
> in this field was interesting - a technical triumph - but financially
> I got stitched up.

I'm making progress, I got basic text based CGI's working, but I'm having
difficulty with other types on content.

Quote
> IMO have a separate App that runs CGI - PostMessage will avoid
> problems - and ... unless it is in the spec ... avoid spawning.

Guess what.   It's in the spec!   But I got it working pretty well though.

Regards

Colin Dawson.

Re:Building a web server.


On Tue, 18 Dec 2001 12:00:06 -0000, "Colin Dawson"

Quote
<n...@cdawson.tele2.co.uk> wrote:
>> IMO CGI is a waste of space - unless one is writing to a spec.

>Got it in one, I'm writing to a spec. And why yes it is literally a waste of
>space, it loads a whole new exe for every single call!
Right. Apologies.

>> Any half decent Webserver is going to be up, alive and waiting for
>> requests from the HTML 'processor'.

By that I misspoke - I mean't POST/GET server (DataServer) - not the
bit that handles TCP/IP
Quote

<snip>

Sometimes I reckon that programming is prostitution - sometimes I get
confused by what I reckon.

The main thing is to totally divorce the *real* webserver from any of
the 'so called' interfaces with 3rd party Apps.

Personally, if I had to jump through this hoop again, I would put the
'CGI Servers' on separate hardware.

'Good fences make good neighbours'

Re:Building a web server.


1) Create a web server application (stand alone CGI applicaiton)
2) Right click on the form and get to action editor
3) Add an action with a proper pathinfo (say func1)
4) Create exe say abc.exe
5) PLace exe in your wwwroot (eg)
6) Give execute permissions to your exe
7) Call func1 using eg http://domain.com/abc.exe/func1
8) Calling the exe from a webpage, you can post any parameters and
retrieve them in func1 using request object. You can use response
object to move further.

Shahzad

Other Threads