import socket
import threading

port = 8080

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('0.0.0.0', port))

server_socket.listen(8)
print("started. listening on 8080 on all interfaces...")

def handle_client(client_socket):
    while 1:
        request = client_socket.recv(8192).decode('utf-8')
        print("recieved: " + str(request))

        response = "data received by server:" + str(request)
        client_socket.send(response.encode('utf-8'))

while 1:
    client_socket, address = server_socket.accept()
    print("connection accepted from " + str(address))
    
    client_thread = threading.Thread(target=handle_client, args=(client_socket,))
    client_thread.start()

server_socket.close()
