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:
"""
Chat client
"""
MSGLEN = 512
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......@@ -14,22 +15,20 @@ class Client:
def send(self, msg):
totalsent = 0
while totalsent < MSGLEN:
while totalsent < self.MSGLEN:
sent = self.sock.send(msg[totalsent:])
if not sent:
raise RuntimeError("socket connection broken")
totalsent = totalsent + sent
def receive(self):
msg = ''
while len(msg) < MSGLEN:
chunk = self.sock.recv(MSGLEN-len(msg))
while True:
chunk = self.sock.recv(1-len(msg))
if not chunk:
raise RuntimeError("socket connection broken")
msg = msg + chunk
return msg
print '< %s' % chunk
if __name__ == '__main__':
client = Client()
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