title: Python tcp socket
body: <p>i'm new in python and coding. I want to do a project that contain TCP socket Server and Client. the server need to read some text data from Json or just text.txt. and send every 5 sec to client.
  I have some start code that i writed, and  stuck ... over it code..
  Need some halp from pythons prof ))
  Thank</p>
  <pre><code>#Server
  import socket 
  from threading import Thread 
  from socketserver import ThreadingMixIn 
   
  
  class ClientThread(Thread): 
   
      def __init__(self,ip,port): 
          Thread.__init__(self) 
          self.ip = ip 
          self.port = port 
          print (&quot;[+] New server socket thread started for &quot; + ip + &quot;:&quot; + str(port)) 
   
      def run(self): 
          while True : 
              data = conn.recv(2048) 
              print (&quot;Server received data: &quot;, data)
              conn.send(data)  
   
  TCP_IP = '127.0.0.1' 
  TCP_PORT = 50654 
  BUFFER_SIZE = 1024  
   
  tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  tcpServer.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
  tcpServer.bind((TCP_IP, TCP_PORT)) 
  threads = [] 
   
  while True: 
      tcpServer.listen(4) 
      print (&quot;Water-Station: Waiting for connections from clients...&quot;) 
      (conn, (ip,port)) = tcpServer.accept() 
      newthread = ClientThread(ip,port) 
      newthread.start() 
      threads.append(newthread) 
      data = conn.recv(2048)
  </code></pre>
  <p>for t in threads:
  t.join()
  if not data: break</p>
  <p>#Client</p>
  <pre><code>import socket
  import sys
  
  HOST = '127.0.0.1'
  PORT = 50654
  addr = (HOST,PORT)
  
  socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  socket.connect(addr)
  
  
  data = input('write to server: ')
  if not data : 
      socket.close() 
      sys.exit(1)
  
  data = str.encode(data)
  socket.send(data)
  data = bytes.decode(data)
  data = socket.recv(1024)
  print(data)
  </code></pre>