title: Server send data in python
body: <p>I'm writing a simple client server app in python, where the client is listening every type of data entering in the specific port, and I want to when receiving a data flow, send back to the connected client (which have a dinamic ip) a string, in this case "001". But when I try to send the message, it fails! </p>
  
  <pre><code>#!/usr/bin/env python
  
  import socket
  
  TCP_IP = '192.168.1.115'        
  TCP_PORT = 55001   
  BUFFER_SIZE = 1024      
  MESSAGE = '01'  
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    
  s.bind((TCP_IP, TCP_PORT))     
  s.listen(1)     
  
  conn, addr = s.accept()         
  print ('Connection address:', addr)      
  while 1:       
      data = conn.recv(BUFFER_SIZE)     
      if not data: break      
      print ('received data:', data)      
      conn.send(data)  # echo       
  
  print ('Sending data to client...')   
  
  addr change every connection .. i cannot manage this! 
  
  s.connect((addr, TCP_PORT))
  s.send(MESSAGE)
  data = s.recv(BUFFER_SIZE)
  s.close()   
  </code></pre>