title: Using simple sockets in a client/server in Python - What am I doing wrong?
body: <p>I'm making a simple Python script using sockets. This is my client code:</p>
  
  <pre><code>import socket
  
  s = socket.socket()
  host = "172.31.26.54"
  port = 1337
  print("Attempting to connect...")
  s.connect((host, port)) 
  print("Connected. Now receving data from host.")
  print s.recv(1024)
  s.close()
  </code></pre>
  
  <p>This is my server code:</p>
  
  <pre><code>import socket
  
  s = socket.socket()
  host = socket.gethostname()
  print(host)
  port = 1337
  s.bind((host, port))
  
  s.listen(5)
  while True:
      c, addr = s.accept()
      print 'recived connection from ', addr
      c.send("Thank you for connecting. It really means a lot to me.")
      c.close()
  </code></pre>
  
  <p>Note: The "<code>host = "172.31.26.54</code>" in the client code is because the server code prints (in line 5) "<code>ip-172-31-26-54</code>" when run.</p>
  
  <p>When I run the server code, then change in the client <code>host</code> to <code>socket.gethostname()</code> and run it on the server, it works perfectly. But when I run the code on different machines, the client just prints "Attempting to connect..." and gets stuck.</p>
  
  <p>Edit: I just tried it using the public ip instead of the private ip. That didn't work either.</p>
  
  <p>What am I doing wrong?</p>