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.

Server-Application.py 832B

5 years ago
123456789101112131415161718192021
  1. import socket
  2. s = socket.socket() # get instance
  3. host = socket.gethostname() # get the hostname
  4. port = 12345 # initiate port no above 1024
  5. s.bind((host, port)) # bind host address and port together
  6. s.listen() # configure how many client the server can listen simultaneously
  7. (connection, addr) = s.accept() # accept new connection
  8. print('Verbindung von ', addr)
  9. while True:
  10. # receive data stream. it won't accept data packet greater than 1024 bytes
  11. data = connection.recv(1024).decode()
  12. if not data:
  13. # if data is not received break
  14. break
  15. print("from connected user: " + str(data))
  16. connection.send(data.upper().encode())
  17. #data = input(' -> ')
  18. #connection.send(data.encode()) # send data to the client
  19. connection.close() # close the connection