1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 An example of an XML-RPC server in Twisted.
10 An example session (assuming the server is running):
13 >>> s = xmlrpclib.Server('http://localhost:7080/')
20 >>> s.echo("lala", 4, 3.4)
21 ['lala', 4, 3.3999999999999999]
22 >>> s.echo("lala", 4, [1, 2])
27 from twisted.web import xmlrpc
28 from twisted.internet import defer
32 class Echoer(xmlrpc.XMLRPC):
34 An example object to be published.
36 Has five methods accessable by XML-RPC, 'echo', 'hello', 'defer',
37 'defer_fail' and 'fail.
40 def xmlrpc_echo(self, *args):
42 Return all passed args.
46 def xmlrpc_hello(self):
48 Return 'hello, world'.
50 return 'hello, world!'
52 def xmlrpc_defer(self):
54 Show how xmlrpc methods can return Deferred.
56 return defer.succeed("hello")
58 def xmlrpc_defer_fail(self):
60 Show how xmlrpc methods can return failed Deferred.
64 def xmlrpc_fail(self):
66 Show how we can return a failure code.
68 return xmlrpclib.Fault(7, "Out of cheese.")
72 from twisted.internet import reactor
73 from twisted.web import server
75 reactor.listenTCP(7080, server.Site(r))
79 if __name__ == '__main__':