how do I read a series of pickled objects from a socket?

Tim Keating mrtact at gmail.com
Tue Nov 16 16:17:16 EST 2004


I would strongly caution you against doing this, unless you are
*positive* you can secure that endpoint at the network level.
Promiscuously accepting arbitrary python objects to execute from an
open network connection is a recipe for disaster IMHO.

OTOH, if you are convinced this is how you want to do this . . . when
you send the pickle, send a fixed size length field (set to the size of
the pickle) first. So the pseudocode would look something like:

size = conn.recv(4)
data = conn.recv(size)
obj = pickle.loads(data)

Also, you probably want to have a look at the select module, unless you
never want your server to shut down :-)

Tim Keating




More information about the Python-list mailing list