I'm building a TCP server using the SocketServer module in python.
As it seems to me, SocketServer.TCPServer functionality is destined to reply to a client that sent a request to the server but not for random communication between the server and the client. For example - Chat between the server and the client..
Is there any way to just send a message to some client registered to the server?
My code for now:
import SocketServer
import chathandler
import threading
PORT = 12345
def do_main():
global httpd
Handler = chathandler.ChatHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "Serving at port:", PORT
httpd.serve_forever()
if __name__ == '__main__':
server_thread = threading.Thread(target = do_main)
server_thread.start()
while True:
print "Send message to the clients"
s = raw_input(": ")
# TODO: Send the message!
In this example i want to send the message to all the clients connected to the server.
Thank you!