5 class Myexception(Exception):
6 def __init__(self, faultCode, faultString):
7 self.faultCode = faultCode
8 self.faultString = faultString
11 def __init__(self, sock=None):
13 self.sock = socket.socket(
14 socket.AF_INET, socket.SOCK_STREAM)
17 self.sock.settimeout(60)
18 def connect(self, host, port=False):
20 protocol, buf = host.split('//')
21 host, port = buf.split(':')
22 self.sock.connect((host, int(port)))
24 self.sock.shutdown(socket.SHUT_RDWR)
26 def mysend(self, msg, exception=False):
27 msg = cPickle.dumps(msg)
29 self.sock.send('%8d' % size)
30 self.sock.send(exception and "1" or "0")
32 while totalsent < size:
33 sent = self.sock.send(msg[totalsent:])
35 raise RuntimeError, "socket connection broken"
36 totalsent = totalsent + sent
40 chunk = self.sock.recv(8 - len(buf))
42 raise RuntimeError, "socket connection broken"
45 buf = self.sock.recv(1)
51 while len(msg) < size:
52 chunk = self.sock.recv(size-len(msg))
54 raise RuntimeError, "socket connection broken"
56 res = cPickle.loads(msg)
57 if isinstance(res,Exception):
59 raise Myexception(exception, str(res))