From 00834eb1be77aa82b32b0ef5da62218d0b8caef5 Mon Sep 17 00:00:00 2001 From: Nadege Date: Fri, 18 Oct 2019 09:42:28 +0200 Subject: [PATCH] Gesteuerter Verbindungsabbau --- client.py | 25 +++++++++++++++++-------- server.py | 13 +++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/client.py b/client.py index c4f6df2..f0c1f4b 100644 --- a/client.py +++ b/client.py @@ -1,13 +1,22 @@ import socket + + s = socket.socket() host = socket.gethostname() -port = 22445 - +port = 22225 s.connect((host, port)) -message = input('eingabe: ') -#bytes = s.sendmsg(message.encode('utf-8')) -test = s.send(message.encode('utf-8')) -msg = s.recv(1024) -print (msg.decode('utf-8')) -s.close() \ No newline at end of file + +#s.send(message.encode('utf-8')) +#bytes = s.recv(1024) +#print (bytes.decode('utf-8')) +#s.close() +message = 'hi' +while message != 'STOP': + message = input('eingabe: ') + s.send(message.encode('utf-8')) + bytes = s.recv(4096) + print(bytes.decode('utf-8')) +else: + print(message) + s.close() \ No newline at end of file diff --git a/server.py b/server.py index 54bc9ab..da597fb 100644 --- a/server.py +++ b/server.py @@ -2,16 +2,17 @@ import socket s = socket.socket() host = socket.gethostname() -port = 22445 +port = 22225 s.bind((host, port)) s.listen() - -while True: - (connection, addr) = s.accept() +(connection, addr) = s.accept() +msg = 'test' +while msg != 'STOP': print('verbindung von ', addr) - bytes = connection.recv(1024) + bytes = connection.recv(4096) msg = bytes.decode('utf-8') msg = msg.upper() connection.send(msg.encode('utf-8')) - connection.close() \ No newline at end of file +else: + connection.close()