Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b88b4863
Commit
b88b4863
authored
Dec 01, 2004
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
parent
656f7d76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
Doc/lib/libsimplexmlrpc.tex
Doc/lib/libsimplexmlrpc.tex
+36
-5
No files found.
Doc/lib/libsimplexmlrpc.tex
View file @
b88b4863
...
...
@@ -88,18 +88,49 @@ simple, stand alone XML-RPC servers.
Example:
\begin{verbatim}
class MyFuncs:
def div(self, x, y) : return x // y
from SimpleXMLRPCServer import SimpleXMLRPCServer
# Create server
server = SimpleXMLRPCServer(("localhost", 8000))
server.register
_
function(pow)
server.register
_
function(lambda x,y: x+y, 'add')
server.register
_
introspection
_
functions()
# Register pow() function; this will use the value of
# pow.
__
name
__
as the name, which is just 'pow'.
server.register
_
function(pow)
# Register a function under a different name
def adder
_
function(x,y):
return x + y
server.register
_
function(adder
_
function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register
_
instance(MyFuncs())
# Run the server's main loop
server.serve
_
forever()
\end{verbatim}
The following client code will call the methods made available by
the preceding server:
\begin{verbatim}
import xmlrpclib
s = xmlrpclib.Server('http://localhost:8000')
print s.pow(2,3) # Returns 2**3 = 8
print s.add(2,3) # Returns 5
print s.div(5,2) # Returns 5//2 = 2
# Print list of available methods
print s.system.listMethods()
\end{verbatim}
\subsection
{
CGIXMLRPCRequestHandler
}
The
\class
{
CGIXMLRPCRequestHandler
}
class can be used to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment