Commit 0e35d6c6 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Merge branch 'master' of ssh://vo20.nl/home/git/repos/uva

parents 423f97c2 804145da
...@@ -5,6 +5,7 @@ class Client: ...@@ -5,6 +5,7 @@ class Client:
""" """
Chat client Chat client
""" """
MSGLEN = 512
def __init__(self): def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
...@@ -14,22 +15,20 @@ class Client: ...@@ -14,22 +15,20 @@ class Client:
def send(self, msg): def send(self, msg):
totalsent = 0 totalsent = 0
while totalsent < MSGLEN: while totalsent < self.MSGLEN:
sent = self.sock.send(msg[totalsent:]) sent = self.sock.send(msg[totalsent:])
if not sent: if not sent:
raise RuntimeError("socket connection broken") raise RuntimeError("socket connection broken")
totalsent = totalsent + sent totalsent = totalsent + sent
def receive(self): def receive(self):
msg = '' while True:
while len(msg) < MSGLEN: chunk = self.sock.recv(1-len(msg))
chunk = self.sock.recv(MSGLEN-len(msg))
if not chunk: if not chunk:
raise RuntimeError("socket connection broken") raise RuntimeError("socket connection broken")
msg = msg + chunk print '< %s' % chunk
return msg
if __name__ == '__main__': if __name__ == '__main__':
client = Client() client = Client()
client.connect('ow150.science.uva.nl', 16897) client.connect('ow150.science.uva.nl', 16897)
print '< %s' % client.receive() client.receive()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment