title: python Socket server with real ip address
body: <p>I am playing with my python server, but I'm through with using localhost and I want to go over the internet. My code thus-far is:</p>
  
  <pre><code>import socket
  import threading
  import socketserver
  
  class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
  
      def handle(self):
          data = self.request.recv(1024)
          cur_thread = threading.current_thread()
          response = "{}: {}".format(cur_thread.name, data)
          self.request.sendall(b'worked') 
  
  class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
      pass
  
  def client(ip, port, message):
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.connect((ip, port))
      try:
          sock.sendall(message)
          response = sock.recv(1024)
          print("Received: {}".format(response))
      finally:
          sock.close()
  
  if __name__ == "__main__":
      # Port 0 means to select an arbitrary unused port
      HOST, PORT = "0.0.0.0", 9001
  
      server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
      ip, port = server.server_address
  
      # Start a thread with the server -- that thread will then start one
      # more thread for each request
      server_thread = threading.Thread(target=server.serve_forever)
      # Exit the server thread when the main thread terminates
      server_thread.daemon = True
      server_thread.start()
      print("Server loop running in thread:", server_thread.name)
      ip = '12.34.56.789' #Not my real ip address This is just to hide my ip
      print(ip, PORT)
  
      client(ip, PORT, b'Hello World 1')
      #client(ip, port, b'Hello World 2')
      #client(ip, port, b'Hello World 3')
  
      server.shutdown()
  </code></pre>
  
  <p>When I run this i get the error:</p>
  
  <pre><code>Server loop running in thread: Thread-1
  12.34.56.789 9001
  Traceback (most recent call last):
    File "C:/Python32/serverTesty.py", line 43, in &lt;module&gt;
      client(ip, PORT, b'Hello World 1')
    File "C:/Python32/serverTesty.py", line 18, in client
      sock.connect((ip, port))
  socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
  </code></pre>
  
  <p>I know the port works because when I use canyouseeme.org on port 9001 when my program is running it says its active and working. So I think I just have my connection wrong somewhere.</p>