From https://stackoverflow.com/questions/17453212/multi-threaded-tcp-server-in-python ```python #!/usr/bin/env python import socket, threading class ClientThread(threading.Thread): def __init__(self,ip,port,sock): threading.Thread.__init__(self) self.ip = ip self.port = port self.socket = sock print("[+] New thread started for "+ip+":"+str(port)) def run(self): print("Connection from : "+ip+":"+str(port)) self.socket.send("\nWelcome to the server\n\n".encode()) data = "dummydata" while len(data := self.socket.recv(2048)) > 0: print("Client sent : "+data.decode()) self.socket.send("You sent me : ".encode()+data) print("Client disconnected...") host = "0.0.0.0" port = 9999 tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcpsock.bind((host,port)) threads = [] while True: tcpsock.listen(4) print("\nListening for incoming connections...") (clientsock, (ip, port)) = tcpsock.accept() newthread = ClientThread(ip, port, clientsock) newthread.start() threads.append(newthread) for t in threads: t.join() ```