############################################################################### # The communication module (communication.py) ############################################################################### import cPickle import socket import struct marshall = cPickle.dumps unmarshall = cPickle.loads def send(channel, args): #print "will send: ", args args+="\n" buf = args #marshall(args) #value = socket.htonl(len(buf)) value = str(len(buf)) #size = struct.pack("i",value) #rint "length: ",len(buf) #print "SIZE: ",repr(size) #channel.send(value) buf+="\0" channel.send(buf) #print 'sending: ',buf #print 'sent' def receive(channel): size = struct.calcsize("L") size = channel.recv(size) print "rec size: ",size try: size = socket.ntohl(struct.unpack("i", size)[0]) #print "unpacked: ",size except struct.error, e: return '' buf = "" while len(buf) < size: buf = channel.recv(size - len(buf)) return unmarshall(buf)[0]