title: How to forward port for server socket using python codes?
body: <p>I'm very new to socket programming and just tried to write a simple server/client script. When I tried to communicate with them in my own device, it worked. But when I gave my script to my friend so we would communicate remotely, it didn't work (I didnt use <code>'localhost'</code> as <code>hostname</code>). </p>
  
  <p>Then he forwarded a port using HTTP interface of his router and tried to connect it with a website that tests if a port is forwarded, it was positive (my script didn't connect but this is not our topic). </p>
  
  <p>So I realized I have to forward the port that my server is going to use as well! But the router that I'm using doesn't belong to me, so I can't reach the HTTP interface. In this case my program has to forward a port. But I don't know how to do it and I could not find an example or one that is at my level.</p>
  
  <p>I think this is possible, because apps we use do it every time. I just need some help to figure it out. Thanks...</p>
  
  <p>My little script:</p>
  
  <pre><code>import socket
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  print('1. Server')
  print('2. Client')
  r = int(input("I'm going to be... "))
  
  if r == 1:
  
      host = socket.gethostname()
      port = int(input('My port will be... (0 for auto) '))
      s.bind((host, port))
      sockName = s.getsockname()
  
      print("\nYour Hostname: %s \nYour Port: %d" % (sockName[0], sockName[1]))
  
      #s.listen(int(input('Listen for ... clients')))
      input('Enter to listen...')
      print('Listening...')
      s.listen(1)
  
      for i in range(1):
          client, address = s.accept()
          print("{}:{} connected!".format(address[0], address[1]))
  
          message = input('Your message (/c to close): ')
          if message == '/c':
              client.send(message)
              print('You sent: ', message.encode('UTF-8'))
          else:
              client.close()
              s.close()
              break;
  
  
  elif r == 2:
  
      host = input('The Hostname of Server is... ')
      port = int(input('The Port of Server is... '))
  
      print("\nServer's Hostname: %s \nServer's Port: %d" % (host, port))
  
      input('Enter to connect...')
      s.connect((host, port))
      print('Connected!')
  
      message = s.recv(4096)
      print('Server: ', message.decode('UTF-8'))
  </code></pre>