Foundations of Python Network Programming

(WallPaper) #1
Chapter 18 ■ rpC

339



2


-4


0



The response to the preceding call looks like this:

<?xml version='1.0'?>






0.0
8.0




If this response looks a bit verbose for the amount of data that it is transmitting, then you will be happy to learn
about the RPC mechanism that I’ll tackle next, JSON-RPC.


JSON-RPC

The bright idea behind JSON is to serialize data structures to strings that use the syntax of the JavaScript programming
language. This means that JSON strings could, in theory, be turned back into data in a web browser simply by using
the eval() function. (However, doing so with untrusted data is generally unwise, so most programmers use a formal
JSON parser instead of taking advantage of its compatibility with JavaScript.) By using a syntax specifically designed
for data rather than adapting a verbose document markup language like XML, this remote procedure call mechanism
can make your data much more compact while simultaneously simplifying your parsers and library code.


the JSON-rpC prOtOCOL

purpose: remote procedure calls

Standard: http://json-rpc.org/wiki/specification

runs atop: http

Data types: int; float; unicode; list; dict with unicode keys; None

Libraries: many third-party, including jsonrpclib
Free download pdf