Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cPickle
- import socket
- import struct
- marshall = cPickle.dumps
- unmarshall = cPickle.loads
- def send(sock, *args):
- buff = marshall(args)
- value = socket.htonl(len(buff))
- size = struct.pack("L",value)
- sock.send(size)
- sock.send(buff)
- def receive(sock):
- size = struct.calcsize("L")
- size = sock.recv(size)
- try:
- size = socket.ntohl(struct.unpack("L", size)[0])
- except struct.error, e:
- return ''
- buff = ""
- while len(buff) < size:
- buff = sock.recv(size - len(buff))
- return unmarshall(buff)[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement