
Beyond this, the server will collect incoming messages and then distribute them to the rest of the connected clients. We could display users by IP address, but most people tend to rather come up with some sort of username, so our server will first allow clients to connect and choose a username. From here, we need to come up with some way to identify our unique users. What will the functions of our server be?įirst, the server needs to accept new connections from clients.

To begin, we'll build the chat_server.py. I found a Solution, here is it: import socketWe've made it through the basics of working with sockets, and now we're ready to try to actually build something with them, so, in this sockets with Python tutorial, we're going to build a console-based chat app. I use an inbox method from here and using lect I am able to check if there is input to be read.

Print("Client List Length : ",len(self.clients)) Only send the request back to the sending client and not the targeted client in the client list.Įdit: I found a Solution, here is it: import socket Print("Server loop running in thread:", server_thread.name) # Exit the server thread when the main thread terminates Server_thread = threading.Thread(target=rve_forever) # Start a thread with the server - that thread will then start one

Server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) (response,clientList)Ĭlass ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): Print("Client List Length : ",len(clientList))ĭata = str((1024), 'ascii') I have try to modify the existing code from the exampleĬlass ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): How do i make this into a multi-client server and send the message to all other client? I have to make a multi-client chat room with TCPServer provided by serversocket module in Python.
