1 |
ajm |
1.1 |
#!/usr/bin/python |
2 |
|
|
# |
3 |
ajm |
1.2 |
# Experiments with Pythons XML-RPC implementation |
4 |
ajm |
1.1 |
# - the server |
5 |
|
|
# |
6 |
ajm |
1.2 |
# $Id: xmlrpcserver.py,v 1.1 2003/11/09 21:02:45 ajm Exp $ |
7 |
ajm |
1.1 |
|
8 |
|
|
from SimpleXMLRPCServer import * |
9 |
|
|
|
10 |
|
|
class ServerImpl(SimpleXMLRPCServer): |
11 |
|
|
|
12 |
|
|
def serve_forever(self): |
13 |
|
|
print '[server] starting up' |
14 |
ajm |
1.2 |
self.run = True |
15 |
|
|
while self.run: |
16 |
ajm |
1.1 |
self.handle_request() |
17 |
|
|
|
18 |
|
|
print '[server] shutting down' |
19 |
|
|
self.socket.close() |
20 |
|
|
|
21 |
|
|
class ServerFunctions: |
22 |
|
|
|
23 |
|
|
# we pass in a ref to the server |
24 |
|
|
# that these functions will be used in |
25 |
|
|
# so they can interact...I'm guessing |
26 |
|
|
# this is clean?...who knows :) |
27 |
|
|
def __init__(self, server): |
28 |
|
|
self.server = server |
29 |
|
|
|
30 |
|
|
def die(self): |
31 |
|
|
"""die() => kills the server""" |
32 |
ajm |
1.2 |
self.server.run = False |
33 |
ajm |
1.1 |
return 1 |
34 |
|
|
|
35 |
|
|
def remoteprint(self, text): |
36 |
|
|
"""print('HelloWorld') => prints HelloWorld""" |
37 |
|
|
print '[server] got:', text |
38 |
|
|
return 1 |
39 |
|
|
|
40 |
|
|
def main(): |
41 |
|
|
print '--- i-scream.org XML-RPC test server ---' |
42 |
|
|
|
43 |
|
|
server = ServerImpl(('127.0.0.1', 8000), logRequests=0) |
44 |
|
|
server.register_instance(ServerFunctions(server)) |
45 |
|
|
server.register_introspection_functions() |
46 |
|
|
server.register_multicall_functions() |
47 |
|
|
server.serve_forever() |
48 |
|
|
|
49 |
|
|
if __name__=='__main__': |
50 |
|
|
main() |