|
123456789101112131415161718192021 |
- import socket
-
- s = socket.socket() # get instance
- host = socket.gethostname() # get the hostname
- port = 12345 # initiate port no above 1024
- s.bind((host, port)) # bind host address and port together
- s.listen() # configure how many client the server can listen simultaneously
-
- (connection, addr) = s.accept() # accept new connection
- print('Verbindung von ', addr)
- while True:
- # receive data stream. it won't accept data packet greater than 1024 bytes
- data = connection.recv(1024).decode()
- if not data:
- # if data is not received break
- break
- print("from connected user: " + str(data))
- connection.send(data.upper().encode())
- #data = input(' -> ')
- #connection.send(data.encode()) # send data to the client
- connection.close() # close the connection
|