Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how do I read a series of pickled objects from a socket?

Reply
Thread Tools

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

 
 
Ryan Grow
Guest
Posts: n/a
 
      11-16-2004
Hi,

I am trying to figure out the correct and most
reliable way to read a series of pickled objects from
a socket.
I've found examples that do something like this:

while 1:
data = conn.recv(500)
obj = pickle.loads(data)
# do stuff with object

I don't think the above example would work for my
application. The above example might work if the
server never expects to get more than one object on
the socket at a time.

The server I'm writing will get a series of objects so
it will need to know where each pickled object ends in
the stream so it knows where to start reading the next
object from.

Is there a correct way to identify the terminator of a
pickled object? Is there a standard and correct way
for the pickle module to easily read pickled objects
from a socket?


Thanks,

Ryan



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com


 
Reply With Quote
 
 
 
 
Tim Keating
Guest
Posts: n/a
 
      11-16-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: Pickled objects over the network Jean-Paul Calderone Python 3 07-19-2007 09:25 PM
Latest errors on pickled objects and blob datatypes in mysql krishnakant Mane Python 2 05-07-2007 05:57 PM
is there a module to work with pickled objects storage in database? krishnakant Mane Python 2 05-04-2007 04:47 PM
how fast can you pingpong pickled objects? Bram Stolk Python 0 12-12-2005 04:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57