title: Python TCP Server using select()
body: <p>this is my first entry @stackoverflow;-))</p>
  <p>I need a Python3 TCP server, which sends all inputs of the clients to the other participants. The server works, but unfortunately the message is only returned to the sending client. As soon as the second client sends something, it gets all entries.The entries are therefore available in the output queue.</p>
  <p>Why are the entries not recognized by select ()?</p>
  <p>Thx for the support.</p>
  <p>`</p>
  <h1></h1>
  <pre><code>import select
  import socket
  import sys
  import queue
  
  server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  server.setblocking(0)
  
  server_address = ('192.168.100.28', 8888)
  print (&quot;starting up on %s port %s&quot; % server_address)
  server.bind(server_address)
  
  server.listen(5)
  
  inputs = [ server ]
  outputs = [ ]
  message_queues = {}
  
  
  
  
  while inputs:
      print (&quot;\nwaiting for the next event&quot;)
      readable, writable, exceptional = select.select(inputs, outputs, inputs)
  </code></pre>
  <h1>Handle inputs</h1>
  <pre><code>for s in readable:
  
      if s is server:
          # A &quot;readable&quot; server socket is ready to accept a connection
          connection, client_address = s.accept()
          print (&quot;new connection from&quot;, client_address)
          connection.setblocking(0)
          inputs.append(connection)
  
          # Give the connection a queue for data we want to send
          message_queues[connection] = queue.Queue()
      else:
          data = s.recv(1024)
          if data:
              # A readable client socket has data
              print ('received &quot;%s&quot; from %s' % (data, s.getpeername()))
              # Add output channel for response
              #message_queues[s].put(data)
              if s not in outputs:
                  outputs.append(s)
              for aQueue in message_queues:
                  message_queues[aQueue].put(data)
                  # AQueue.send (&quot;Test&quot;.encode())
          else:
              # Interpret empty result as closed connection
              print (&quot;closing&quot;, client_address, &quot;after reading no data&quot;)
              # Stop listening for input on the connection
              if s in outputs:
                  outputs.remove(s)
              inputs.remove(s)
              s.close()
  
              # Remove message queue
              del message_queues[s]
  </code></pre>
  <h1>Handle outputs</h1>
  <pre><code>for s in writable:
      try:
          next_msg = message_queues[s].get_nowait()
      except queue.Empty:
          # No messages waiting so stop checking for writability.
          print (&quot;output queue for&quot;, s.getpeername(), &quot;is empty&quot;)
          outputs.remove(s)
      else:
          print ('sending &quot;%s&quot; to %s' % (next_msg, s.getpeername()))
          s.send(next_msg)
  </code></pre>
  <h1>Handle &quot;exceptional conditions&quot;</h1>
  <pre><code>for s in exceptional:
      print (&quot;handling exceptional condition for&quot;, s.getpeername())
      # Stop listening for input on the connection
      inputs.remove(s)
      if s in outputs:
          outputs.remove(s)
      s.close()
  
      # Remove message queue
      del message_queues[s]
  </code></pre>
  <p>`</p>