Lösungen der Aufgaben vom Kurs MEIM1 - Web Engineering von Prof. Hofmann
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

protocol-server.py 683B

1234567891011121314151617181920212223242526272829
  1. #! /usr/bin/env python3
  2. import socket
  3. HOST = socket.gethostname()
  4. PORT = 60001
  5. SOCKET = socket.socket()
  6. try:
  7. SOCKET.bind((HOST, PORT))
  8. SOCKET.listen()
  9. while True:
  10. conn, addr = SOCKET.accept()
  11. print(f"Client {addr[0]} connected at port {addr[1]}.")
  12. while True:
  13. #print("Running...")
  14. msg = conn.recv(1024)
  15. msg = msg.decode("utf-8")
  16. upper_msg = msg.upper()
  17. if msg and msg == "STOP":
  18. break
  19. else:
  20. conn.send(upper_msg.encode("utf-8"))
  21. conn.close()
  22. print("Client disconnected. Waiting for new client")
  23. finally:
  24. SOCKET.close()