Skip to content
Snippets Groups Projects
Commit b691a5fa authored by Sander van Veen's avatar Sander van Veen
Browse files

Added initial version of client.py.

parent e47c4809
No related branches found
No related tags found
No related merge requests found
import socket
class Client:
"""
Chat client
"""
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def connect(self, host, port):
self.sock.connect((host, port))
def send(self, msg):
totalsent = 0
while totalsent < 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))
if not chunk:
raise RuntimeError("socket connection broken")
msg = msg + chunk
return msg
if __name__ == '__main__':
client = Client()
client.connect('ow150.science.uva.nl', 16897)
print '< %s' % client.receive()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment