title: python socket connecting to ngrok server
body: <p>So I'm a bit new to python servers and I have made a simple program that sends a message to a server. It works when I set the host as <code>192.168.x.x</code> but I have tried to use ngrok so that way I can access the server if I'm on another network. Howver I can't seem to figure out how to get it to work. This is also probably not the best way to do it so if anyone could suggest a better way that would be great but right now I have:</p>
  <p>A server that's hosted on 192.168.x.x:8080</p>
  <p>An ngrok tunnel that forwards to my ip</p>
  <p>and a client program that sends data to that ngrok address</p>
  <p>Here is the host code:</p>
  <pre><code>import socketserver
  class MyTCPHandler(socketserver.BaseRequestHandler):
      def handle(self):
          # self.request is the TCP socket connected to the client
          self.data = self.request.recv(1024).strip()
          print(&quot;{} wrote:&quot;.format(self.client_address[0]))
          print(self.data)
  if __name__ == &quot;__main__&quot;:
      HOST, PORT = &quot;192.169.x.x&quot;, 8080
      server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
      server.serve_forever()
  </code></pre>
  <p>And here is the client:</p>
  <pre><code>import socket
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
      ip = socket.gethostbyname('http://urlgoeshere.ngrok.io')
      print(ip)
      sock.connect((ip, 8080))
      sock.sendall(bytes(&quot;hello&quot; + &quot;\n&quot;, &quot;utf-8&quot;))
  
  </code></pre>
  <p>The ngrok is:</p>
  <p><code>Forwarding                    http://urlhere.ngrok.io -&gt; http://192.168.x.x</code></p>
  <p>Note: this worked when instead of using ngrok I used my computer IP so I know its not a problem with the host</p>
  <p>No errors but the server does not seem to respond</p>
  <p>Thanks!</p>