title: How to send data to client with conn.send()
body: <p>Im trying to create a simple chat server. I've been able to send information to the server through the client using 'client.send()' but I cannot seem to do the same server->client</p>
  
  <p>I have tried using methods such as conn.send() and conn.sendall(), but (I guess since the code is in a try) they seem to get skipped after the initial conn.send(str.encode("Connected"))</p>
  
  <p>Server code</p>
  
  <pre class="lang-py prettyprint-override"><code>import socket
  from _thread import *
  import sys
  
  server = "192.168.0.4"
  port = 5555
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  try:
      s.bind((server, port))
  except socket.error as e:
      str(e)
  
  s.listen(2)
  print("Waiting for a connection, Server Started")
  
  
  def threaded_client(conn):
      conn.send(str.encode("Connected"))
      reply = ""
      while True:
          conn.send(str.encode(str(reply)))
          try:
              data = conn.recv(2048*1)
              reply = data.decode("utf-8")
  
              if not data:
                  print("Disconnected")
                  break
              else:
                  print("Received: ", reply)
                  print("Sending : ", reply)
  
              conn.sendall(str.encode(reply)) #Where I want to send information to the client
          except:
              break
  
      print("Lost connection")
      conn.close()
  
  
  while True:
      conn, addr = s.accept()
      print("Connected to:", addr)
  
      start_new_thread(threaded_client, (conn,))
  </code></pre>
  
  <p>client code</p>
  
  <pre class="lang-py prettyprint-override"><code>import socket
  
  class Network:
      def __init__(self):
        self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server = "192.168.0.4"
        self.port = 5555
        self.addr = (self.server, self.port)
        self.id = self.connect()
        print(self.id)
  
      def connect(self):
          try:
              self.client.connect(self.addr)
              return self.client.recv(2048).decode()
          except:
              pass
  
      def send(self, data):
          try:
              self.client.send(str.encode(data))
              return self.client.recv(2048).decode()
          except socket.error as e:
              print(e)
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>from network import Network
  n = Network()
  
  while True:
      n.send("sending stuff") #this works/sends properly
  </code></pre>