title: Java clientside socket can't regonize heroku server
body: <p>I have setup a server running using ServerSocket on heroku. I know that heroku defines the port in a system defined variable, and I'm using that as well. Here is the snippet of the server code on Heroku.</p>
  
  <pre><code>ServerSocket serverSocket = null;
  try {
     serverSocket = new ServerSocket(Integer.parseInt(System.getenv("PORT"));
     System.out.println("Booted server.  " + Integer.parseInt(System.getenv("PORT"));
     System.out.println(serverSocket);
  } catch (IOException e) {
     System.err.println("Could not listen on port: " + Integer.parseInt(System.getenv("PORT"));
     System.exit(1);
  }
  Socket clientSocket = null;
      try {
          while (true) {
              clientSocket = serverSocket.accept()
              ConnectionHandler c = new ConnectionHandler(clientSocket);
          }
  </code></pre>
  
  <p>Running that and checking heroku logs shows that the server is running fine, </p>
  
  <pre><code>2013-11-22T03:02:21.940969+00:00 app[web.1]: Booted server.  40506
  2013-11-22T03:02:21.953200+00:00 app[web.1]: ServerSocket[addr=0.0.0.0/0.0.0.0,localport=40506]
  </code></pre>
  
  <p>Next I'm running an android app, that requires to send/receive information. Here is the snippet of code that connects to the port.</p>
  
  <pre><code>clientSocket = new Socket(http://appname.herokuapp.com, 40506);
  </code></pre>
  
  <p>However I get the following in logcat on the above line:</p>
  
  <pre><code>java.net.UnknownHostException: Unable to resolve host "http://appname.herokuapp.com": No address associated with hostname
  at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
  at java.net.InetAddress.getAllByName(InetAddress.java:214)
  at java.net.Socket.tryAllAddresses(Socket.java:108)
  at java.net.Socket.&lt;init&gt;(Socket.java:177)
  at java.net.Socket.&lt;init&gt;(Socket.java:149)
  at com.example.taid.FullscreenActivity.CheckAccount(FullscreenActivity.java:241)
  </code></pre>
  
  <p>What's causing this error? Is that not the correct server address? On the server side, upon accepting a new connection I do have a print statement (testing purposes), and going to the url from web browser it prints the statement, so heroku accepts connection.</p>
  
  <p>Also several things I noticed on Heroku:</p>
  
  <p>1) Every few minutes the port gets incoming connections from a certain ip. During a single run, the ip is same with ports incrementing by 1. What are these connections? Can i stop them?</p>
  
  <p>2) When I use the command to print the variable port (cmd > heroku run echo $PORT), I've realized this port is always different than what my server starts on. So is the problem with this line: System.getenv("PORT") ??</p>
  
  <p>Any help is appreciated, been trying to troubleshoot this for toooooo long.</p>