title: How to keep listening to the connected TCP sockets by "select"
body: <p>All my clients sockets do the same thing: send a package every second(22 bytes) </p>
  
  <p>Server code as below:</p>
  
  <pre><code>import select
  import socket
  import datetime
  SList = []
  
  
  class Tserver:
  
      def __init__(self, portNum):
          host = '127.0.0.1'
          self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
          self.server.bind((host, portNum))
          self.server.listen(1)
  
  
  def GETPACK():
      # function for CRC check
      def CRC(DATA_STR):
          return 1
  
      # generate 100 sockets to listen
      for x in range(100):
          SList.append(Tserver(x+10000))
  
      inputs = []
      # put in inputs
      for x in range(100):
          inputs.append(SList[x].server)
  
      while(True):
          ready_socks, _, _ = select.select(inputs, [], [])
          for sock in ready_socks:
              c, addr = sock.accept()
              while(True):
                  data = c.recv(22)
                  if len(data) == 22:  # To make sure the data-length is 22
                      # Turn the pack string into bytearray
                      data_bytes = bytearray()
                      data_bytes.extend(data)
                      if CRC(data_bytes) == 1:
                          print "Connected from client IP Address:" + str(addr)
                          # ID
                          ID = 256*data_bytes[1] + data_bytes[2]
                          print "ID: ", ID
                          now = datetime.datetime.now()
                          print "now: ", str(now)
  
  if __name__ == "__main__":
      GETPACK()
  </code></pre>
  
  <p>My server can only print the packages sent by the first connected socket.
  And my question is how to print out all message from each ports whenever a package is sent to the server. </p>