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

milan_sanremo hancock.robert at gmail.com
Thu Oct 18 18:21:15 EDT 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
socket.

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


Client
---------
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)
sock.connect(remoteHost)
sock.send(pickledMailbag)

Server
---------
import envelope, mailbag, cPickle, socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(host, port)
sock.listen(5)
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
with
their data?




More information about the Python-list mailing list