title: python3: two clients sending data to server using sockets
body: <p>I'm working with 3 raspberry pi, one as a server and the two others are clients. What I want to do is to make the clients communicate with the server simultaneously, I don't want to wait for client1 communication to be done in order to launch client2 request to the server (which I succeeded to do). However, I want each client to send different data to server at the same time. I tried to use Sockets and threading, like below.</p>
  
  <p>server code: </p>
  
  <pre><code>import socket
  import RPi.GPIO as GPIO
  from threading import Thread 
  
  
  # Multithreaded Python server : TCP Server Socket Thread Pool
  class ClientThread(Thread): 
  
      def __init__(self,ip,port): 
          Thread.__init__(self) 
          self.ip = ip 
          self.port = port 
          print ("[+] New server socket thread started for " + ip + ":" + str(port)) 
  
      def run(self): 
          while True : 
              data = conn.recv(2048) 
              data = data.decode('utf-8')
              print ("Server received data:", data)
              MESSAGE = input("Multithreaded Python server : Enter Response from Server/Enter exit:")
              if MESSAGE == 'exit':
                  break
              conn.send(str.encode(MESSAGE))  # echo 
  
  # Multithreaded Python server : TCP Server Socket Program Stub
  TCP_IP = '' 
  TCP_PORT = 9050 
  BUFFER_SIZE = 2000  # Usually 1024, but we need quick response 
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  
  s.bind((TCP_IP, TCP_PORT)) 
  s.listen(2)
  threads = [] 
  list_data=[]
  
  
  while True: 
  
      print ("Multithreaded Python server : Waiting for connections from TCP clients...") 
      (conn, (ip,port)) = s.accept() 
      data = conn.recv(2048)
      newthread = ClientThread(ip,port) 
      newthread.start() 
      threads.append(newthread)
      list_data.append(data) 
  
  
  for t in threads: 
      t.join()
  </code></pre>
  
  <p>client1 code:</p>
  
  <pre><code>import socket
  import RPi.GPIO as GPIO
  import time
  
  
  host = '192.168.0.198' 
  port = 9050
  BUFFER_SIZE = 2000 
  MESSAGE = input("tcpClient1: Enter message/ Enter exit:")
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  s.connect((host, port))
  
  while MESSAGE != 'exit':
      s.send(str.encode(MESSAGE))     
      data = s.recv(BUFFER_SIZE)
      data = data.decode('utf-8')
      print (" Client2 received data:", data)
      MESSAGE = input("tcpClient2: Enter message to continue/ Enter exit:")
  </code></pre>
  
  <p>client2 code:</p>
  
  <pre><code>import socket
  import RPi.GPIO as GPIO
  import time
  
  import socket 
  
  host = '192.168.0.198'
  port = 9050
  BUFFER_SIZE = 2000 
  MESSAGE = input("tcpClient2: Enter message/ Enter exit:") 
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  s.connect((host, port))
  
  while MESSAGE != 'exit':
      s.send(str.encode(MESSAGE))     
      data = s.recv(BUFFER_SIZE)
      data = data.decode('utf-8')
      print (" Client received data:", data)
      MESSAGE = input("tcpClient2: Enter message to continue/ Enter exit:")
  </code></pre>
  
  <p>when i run, i obtain:
   in the server terminal:</p>
  
  <pre><code>Multithreaded Python server : Waiting for connections from TCP clients...
  [+] New server socket thread started for 192.168.0.197:47012
  Multithreaded Python server : Waiting for connections from TCP clients...
  [+] New server socket thread started for 192.168.0.196:47886
  Multithreaded Python server : Waiting for connections from TCP clients...
  </code></pre>
  
  <p>in client1 terminal:</p>
  
  <pre><code>tcpClient1: Enter message/ Enter exit:begin
  </code></pre>
  
  <p>in client2 terminal:</p>
  
  <pre><code>tcpClient2: Enter message/ Enter exit:begin
  </code></pre>
  
  <p>It seems like server didn't receive or send any data.</p>