Integrating SimpleHTTPServer into asyncore
Ng Pheng Siong
ngps at madcap.dyndns.org
Wed Jul 11 17:54:25 CEST 2001
According to Rick Lee <rwklee at home.com>:
> This is a slightly different question about Medusa. Is there a way to
> dynamically add/remove server IP addresses to/from Medusa as it is
Short answer: Yes, with some additional work.
Longer answer: In Medusa, a "server" is an object that accept()'s on a
socket. When a connection comes in, the "server" instantiates a "channel"
with the connected socket. The "channel" does the actual protocol work on
said connected socket. (See http_server.py's http_server and http_channel
classes. For a heavy-duty example, see Zope's ZServer.)
Typically, in an asyncore-based application, one writes a bunch of
procedural startup code, which includes instantiating one's "servers". The
procedural code then invokes "asyncore.loop()". The app now loops (duh!)
and does its work via the "channels" that are instantiated by the "servers"
in response to socket connections.
I suppose you are interested in adding and removing "servers" while the
application is in asyncore's loop. One way is for your app to first start a
_controller_ "server" with which you communicate, also over sockets, for
this purpose. You'll need to design the controller's protocol (candidate:
XML-RPC request/response) and also implement a client.
The following code is of interest for building the controller "server":
Say you now have a controller from which you can start and stop other
servers within your app. Depending on your threat model, you begin to worry
about the security of your communication with the controller. One simple
answer is to do SSL using M2Crypto. ;-)
Ng Pheng Siong <ngps at post1.com> * http://www.post1.com/home/ngps
Quidquid latine dictum sit, altum viditur.
More information about the Python-list