Browser front-end, python back-end

Peter Hansen peter at engcorp.com
Tue Jan 28 14:35:20 EST 2003


William wrote:
> 
> "Eric Mattes" <ericmattes at yahoo.com> writes:
> 
> > Sorry, I should have been more specific about the intent of this program. I
> > am intending to distribute the program in a form which does not require an
> > internet connection. I wanted a python program to act as a server so that it
> > can receive requests from a browser pointing to localhost.
> >
> > The program is a turn-based game, so it is suitable for web browser
> > implementation. I'm just wondering if its feasable to have the whole app
> > (server and all) in one package.
> >
> 
> Using BaseHTTPServer, we can make an .exe with py2exe. You just run it
> and open your browser to play !

You could also use win32com.client.Dispatch to open IE directly and 
navigate to the home page of your application.  I suppose you can 
also contrive to turn off many features of IE at the same time, for
example preventing navigation outside of your "site", but I have no
idea how to do that.  (But I'd appreciate links to tutorials/guides on
the subject!)

> > My worries about using BaseHTTPServer come from the fact that when I run
> > 'serve_forever()', I need to use the task manager to kill the program. Is
> > there some way around that?
> 
> When you don't whant to use Control-C to kill your server, you have to
> code the suicide and call it with a hidden page, eventualy on an other
> port.

There are some other options.  One is that if you launch the browser
as I mention above, you can probably detect when it is close and use
that as a signal to exit.  You could also encode a "keepalive" signal
into the web pages using Javascript's setInterval() to periodically 
"tickle" the server (e.g. using xml.load() to avoid disturbing the
current page contents).

This is actually an interesting idea, even for a standalone machine.
I recall someone posting a link to a program that sounded like it 
already did all this, several months back.  Maybe Eric should search
for that first.

-Peter




More information about the Python-list mailing list