title: How to initiate a socket connection from server to client?
body: <p>I have setup a tcp socket between a client and a server, very basic. Client side:</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import socket
  
  # create a socket object
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  
  # get local machine name
  host = "81.88.95.250"                      
  
  port = 25000
  
  # connection to hostname on the port.
  s.connect((host, port))                               
  
  # Receive no more than 1024 bytes
  msg = s.recv(1024)                                     
  
  s.close()
  print (msg.decode('ascii'))
  </code></pre>
  
  <p>server side:</p>
  
  <pre><code>#!/usr/bin/env python3
  import socket                                         
  
  # create a socket object
  serversocket = socket.socket(
                  socket.AF_INET, socket.SOCK_STREAM) 
  
  # get local machine name
  host = socket.gethostname()                           
  
  port = 25000                                           
  
  # bind to the port
  serversocket.bind((host, port))                                  
  
  # queue up to 5 requests
  serversocket.listen(5)                                           
  
  while True:
     # establish a connection
     clientsocket,addr = serversocket.accept()      
  
     print("Got a connection from %s" % str(addr))
  
     msg = 'Thank you for connecting'+ "\r\n"
     clientsocket.send(msg.encode('ascii'))
     clientsocket.close()
  </code></pre>
  
  <p>My target is to send notification from client to server, and that's easy. The difficult part is that I also need in some circumstances to start the connection from the server and to send a command to the client and this must be executed as soon as it is received, so I cannot setup a periodic "poll". But I'm quite confused on this part, because the client is behind a NAT, not exposed with a public IP.</p>