title: Server only prints messages from the most recently connected client
body: <p>I'm trying to create a server that accepts multiple clients. The clients can send messages to the server, and the server prints these messages. My code below produces a weird result where only the most recent connection has its messages accepted and printed by the server.</p>
  
  <p><strong>server.py</strong></p>
  
  <pre><code>import socket
  import _thread
  
  HOST = "192.168.1.84"
  PORT = 5000
  
  
  def client_thread(conn):
      welcome_message = "Connected to server " + HOST + ":" + str(PORT) + "\n"
      conn.send(welcome_message.encode("ascii"))
      while True:
          data = connection.recv(2048)
          message = data.decode("ascii")
          if not data:
              break
          print("(" + address[0] + ":" + str(address[1]) + ") " + message)
      connection.close()
  
  
  with socket.socket() as server_socket:
      try:
          server_socket.bind((HOST, PORT))
          server_socket.listen(10)
          print("Server hosted on " + HOST + ":" + str(PORT) + "\n")
          while True:
              connection, address = server_socket.accept()
              _thread.start_new_thread(client_thread, (connection,))
              print("Connection from " + address[0] + ":" + str(address[1]))
  
      except socket.error as error_message:
          print("Error: " + str(error_message))
  </code></pre>
  
  <p><strong>client.py</strong></p>
  
  <pre><code>import socket
  
  HOST = "192.168.1.84"
  PORT = 5000
  
  with socket.socket() as client_socket:
      try:
          client_socket.connect((HOST, PORT))
          data = client_socket.recv(2048)
          print(data.decode("ascii"))
          while True:
              message = input()
              data = message.encode("ascii")
              client_socket.send(data)
      except socket.error as error_message:
          print("Error: " + str(error_message))
  </code></pre>
  
  <p><strong>Problem Output Behavior:</strong></p>
  
  <p>Client 1 can connect to the server and send messages. The server receives and prints these messages fine.</p>
  
  <p>Now when Client 2 connects to the server, Client 1's messages no longer is sent to the server. Now only Client 2 can send messages to the server and have it printed fine.</p>
  
  <p>To further carry this out, Client 3 connects to the server. Now both Client 1's and Client 2's messages aren't sent to the server, only Client 3's messages are.</p>