title: IndexError: list index out of range Multi-threaded server
body: <pre><code>from socket import *
  import thread
  
  
  def thread_handler(connectionSocket, addr):
      while True:
          # Establish the connection
              print ("Ready to serve...")
  
   #           connectionSocket, addr = serverSocket.accept()  
  
  
  
          try:
              message = connectionSocket.recv(1024)
  #            print(message, '::', message.split()[0], ":", message.split()[1])
              filename = message.split()[1]
  #            print(filename, "||", filename[1:])
              f = open(filename[1:], "r")
  
              outputdata = f.read()
  #            print(outputdata)
  
              #Send one HTTP header line into socket
              #Fill in start
              connectionSocket.send('\nHTTP/1.1 200 OK\n\n')
              connectionSocket.send(outputdata)
              #Fill in end
  
              #Send the content of the requested file to the client
              for i in range(0,len(outputdata)):
                  connectionSocket.send(outputdata[i:i+1])
              connectionSocket.send(b'\r\n\r\n')
  
          except IOError:
              #Send response message for file not found
                  #Fill in Start
                  connectionSocket.send('\nHTTP/1.1 404 Not Found\n\n')
                  #Fill in end
  
                  #Close client socket
  
  
  if __name__ == '__main__':
      serverSocket = socket(AF_INET, SOCK_STREAM)
      # Prepare a sever socket
      serverSocket.bind(("localhost", 6789))
      serverSocket.listen(1)
  
  while True:
      print('waiting for connection...')
      connectionSocket, addr = serverSocket.accept()
      print('...connected from:', addr)
      thread.start_new_thread(thread_handler, (connectionSocket, addr))
  
  
  serverSocket.close()
  </code></pre>
  
  <p>I understand how the multi threading works now, but I could not figure out how to build a connection.
  I'm trying to do a multi-threaded version of TCP server. However, it keeps giving "list index out of range":</p>
  
  <pre><code>Ready to serve...
  Unhandled exception in thread started by &lt;function thread_handler at 0x10b9750c8&gt;
  Traceback (most recent call last):
    File "http_server_multi.py", line 16, in thread_handler
      filename = message.split()[1]
  IndexError: list index out of range
  </code></pre>