What Data is Available With a Pickled Object Over a Socket?

milan_sanremo hancock.robert at gmail.com
Fri Oct 19 00:21:15 CEST 2007

I've read the library entry for pickle a couple of times, and I'm
still not
sure what data is maintained when an item is pickled and sent over a

Two importable modules:

class envelope():
	def __init__(self, rec, d):
		self.recipient = rec
		self.listData = d

class mailbag():
	def __init__(self):
		self.dicEnvelope = []

	def addEnvelope(self, uuid, envelope):
		self.dicEnvelope[uuid] = envelope

import envelope, mailbag, cPickle, socket

remoteHost = "999.666.888.777
mb = mailbag()
env1 = envelope('John', ('a', 'b', 'c'))
env2 = envelope('Mary', ('d', 'e', f'))

mb.addEnvelope(1, env1)
mb.addEvenlop(2, env2)

pickledMailbag = cPickle.dump(mb, HIGHEST_PROTOCOL)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

import envelope, mailbag, cPickle, socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(host, port)
conn, addr = sock.accept()
while 1:
    pickledData = conn.recv(1024)
    if not pickledData break

mb = cPickle.load(pickledData)

At this point, does mb contain a dictionary with the two envelopes
their data?

More information about the Python-list mailing list