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.

Prakt1_Socket.py 459B

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
1234567891011121314151617181920
  1. import socket
  2. import string
  3. s = socket.socket()
  4. host = socket.gethostname()
  5. port = 21345
  6. s.bind((host, port))
  7. s.listen()
  8. while True:
  9. (connection, addr) = s.accept()
  10. print('Verbindung von ', addr)
  11. msg = 'Server sagt Hallo'
  12. connection.send(msg.encode('utf-8'))
  13. msg = connection.recv(1024)
  14. msg = (msg.decode('utf-8')).upper()
  15. connection.send(msg.encode('utf-8'))
  16. #msg = msg.decode('utf-8')
  17. #print(msg)
  18. connection.close()