Browse Source

Gesteuerter Verbindungsabbau

master
Nadege 5 years ago
parent
commit
00834eb1be
2 changed files with 24 additions and 14 deletions
  1. 17
    8
      client.py
  2. 7
    6
      server.py

+ 17
- 8
client.py View File

@@ -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()

#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()

+ 7
- 6
server.py View File

@@ -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()
else:
connection.close()

Loading…
Cancel
Save