title: I need the server to send messages to all clients (Python, sockets)
body: <p>This is my server program, how can it send the data received from each client to every other client?</p>
  
  <pre><code>import socket
  import os
  from threading import Thread
  import thread
  
  def listener(client, address):
      print "Accepted connection from: ", address
  
      while True:
          data = client.recv(1024)
          if not data:
              break
          else:
              print repr(data)
              client.send(data)
  
      client.close()
  
  host = socket.gethostname()
  port = 10016
  
  s = socket.socket()
  s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  s.bind((host,port))
  s.listen(3)
  th = []
  
  while True:
      print "Server is listening for connections..."
      client, address = s.accept()
      th.append(Thread(target=listener, args = (client,address)).start())
  
  s.close()
  </code></pre>