The file runxs.py is
shown in Example 10-13,
and actually is the primary script for the XML Switch service. The
XMLSwitchServer
object is an instance
of the BaseHTTPServer.HTTPServer
, so
it is launched accordingly:
import XMLSwitchHandler import BaseHTTPServer XMLSwitchServer = BaseHTTPServer.HTTPServer( ('', 2112), XMLSwitchHandler.XMLSwitchHandler) XMLSwitchServer.handle_request( )
The XMLSwitchHandler
is passed
in at construction time along with the port number to listen to.
Whenever a request comes in, the HTTPServer
just launched invokes its XMLSwitchHandler
to manage the request.
In this example, however, the handle_request
method is used. Now the server
runs only until it services one request. You can change this by calling
XMLSwitchServer.serve_forever
.
Regardless, you can always use runxs.py, shown in Example 10-13, to start your
server.
""" runxs.py """ import XMLSwitchHandler import BaseHTTPServer # start up print "XMLSwitch starting..." XMLSwitchServer = BaseHTTPServer.HTTPServer( ('', 2112), XMLSwitchHandler.XMLSwitchHandler) # run server print "Running..." for x in range(10): XMLSwitchServer.handle_request( )
To launch the server, use a spare command or shell prompt:
G:pythonxmlc10> python runxs.py XMLSwitch starting... Running...
The server outputs requests as they happen:
centauri - - [03/Jun/2001 15:12:02] "POST / HTTP/1.0" 200 - centauri - - [03/Jun/2001 15:12:04] "POST / HTTP/1.0" 200 -
Beyond this, the only interaction you have with the server is by running xcs.py as shown in Example 10-10.
3.136.233.153