I need a simple socket server which will echo a client message to all connected clients.
I've found this easy py script below, but it only echos the string to the client that sent the message. Any way to mod this so that it will send the message to all clients connected? ...yes, this is probably really simple, but I have very little understanding of python...
from socket import * import threading import thread def handler(clientsock,addr): while 1: data = clientsock.recv(BUFSIZ) if not data: break msg = 'echoed:... ' + data clientsock.send(msg) clientsock.close() if __name__=='__main__': HOST = 'localhost' PORT = 5555 BUFSIZ = 1024 ADDR = (HOST, PORT) serversock = socket(AF_INET, SOCK_STREAM) serversock.bind(ADDR) serversock.listen(2) while 1: print 'waiting for connection...' clientsock, addr = serversock.accept() print '...connected from:', addr thread.start_new_thread(handler, (clientsock, addr))