[Tutor] Data exchange formats...

Alan Gauld alan.gauld at btinternet.com
Mon Jun 21 01:47:10 CEST 2010

"Modulok" <modulok at gmail.com> wrote

> What's the best format to send data across the wire between 
> processes?

That depends on what you measure as 'best' - data volume, speed of
transmission, security, data complexity, flexibility, ease of decoding 
etc etc.

> a server via a TCP socket. Things like 'count = 10, name="foo"' and 
> so
> forth. Basic values.

You could use the struct module to pack them as binary then unpack
at the far end. Its space efficient and relatively easy to pack/unpack
and marginally more secure than plain text. But only marginally!

> I would use something like the 'pickle' module to
> pack them up send as encoded strings, which would then be loaded on
> the server. It'd be nice, but the server has no authentication.
> Therefore:
> "Warning The pickle module is not intended to be secure against
> erroneous or maliciously constructed data. Never unpickle data
> received from an untrusted or unauthenticated source."

That might not be a problem if security is not an issue.

> Currently I'm sending strings and using regular expressions on the
> server to pluck out the needed data, but thought there must be
> something cleaner, nicer and better. Ideas?

XML? There are a variety of parsers out there.
http form submission? Again there are numerous CGI solutions.
You could even use https for security...

Or you can construct a plain text string - comma separated
using the csv module, and then encryupt using one of the
crypto algorithms available.

It all depends on what you want to do.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list