Reputation: 867
I am trying to write a program that allows for multiple connections and the server operator can send messages to all the connected clients. I have sorted out the problem of allowing multiple connections using simple threading, now my problem is the message doesn't send to all the connected clients all at once, I have to send the message multiple times to send it to ever client.
def send(add, conn, port, s):
while True:
message = raw_input("Message: ")
add.send(message)
def server(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', port))
s.listen(10))
print "Waiting for connections..."
while True:
a,b = s.accept()
print b, "connected"
connections.append(b)
thread = threading.Thread(target=send, args=(a, b, port, s))
thread.start()
threads.append(thread)
Upvotes: 0
Views: 374
Reputation: 84189
This is how TCP works. There's no broadcast facility. If you need to send the same message to multiple connected clients, you have to do it for each socket.
Upvotes: 1