title: Python SocketServer: sending to multiple clients?
body: <p>Well, I'm trying to build a small python prgram with a SocketServer that is supposed to send messages it receives to all connected clients. I'm stuck, I don't know how to store clients on the serverside, and I don't know how to send to multiple clients. Oh and, my program fails everytime more then 1 client connects, and everytime a client sends more then one message...</p>
  
  <p>Here's my code until now: </p>
  
  <pre><code>        print str(self.client_address[0])+' connected.'
      def handle(self):
          new=1
          for client in clients:
              if client==self.request:
                  new=0
          if new==1:
              clients.append(self.request)
          for client in clients:
              data=self.request.recv(1024)
              client.send(data)
  
  class Host:
      def __init__(self):
          self.address = ('localhost', 0)
          self.server = SocketServer.TCPServer(self.address, EchoRequestHandler)
          ip, port = self.server.server_address
          self.t = threading.Thread(target=self.server.serve_forever)
          self.t.setDaemon(True)
          self.t.start()
          print ''
          print 'Hosted with IP: '+ip+' and port: '+str(port)+'. Clients can now connect.'
          print ''
      def close(self):
          self.server.socket.close()
  
  class Client:
      name=''
      ip=''
      port=0
      def __init__(self,ip,port,name):
          self.name=name
          self.hostIp=ip
          self.hostPort=port
          self.s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.s.connect((self.hostIp, self.hostPort))
      def reco(self):
          self.s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.s.connect((self.hostIp, self.hostPort))
      def nick(self,newName):
          self.name=newName
      def send(self,message):
          message=self.name+' : '+message
          len_sent=self.s.send(message)
          response=self.s.recv(len_sent)
          print response
          self.reco()
      def close(self):
          self.s.close()
  </code></pre>
  
  <p>Obviously I have no idea what I'm doing, so any help would be great.<br>
  Thanks in advance!</p>
  
  <p>Edit: I'm using Python 2.7 on Windows Vista.</p>