title: Android Server Socket
body: <p>I am unable to reach the Android Server on the emulator from a program on my desktop, how do I solve it?</p>
  
  <p>Some code (from <a href="https://stackoverflow.com/questions/13436181/how-to-find-lan-ip-address-of-android-device">How to find LAN ip address of android device?</a>):</p>
  
  <pre><code>public static ArrayList&lt;String&gt; getSelfIP(){
      try {
          ArrayList&lt;String&gt; ipList = new ArrayList&lt;&gt;();
          for (Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
              NetworkInterface intf = en.nextElement();
              for (Enumeration&lt;InetAddress&gt; enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                  InetAddress inetAddress = enumIpAddr.nextElement();
                  if (!inetAddress.isLoopbackAddress()) {
                      ipList.add(inetAddress.getHostAddress().toString());
                  }
              }
          }
  
          return ipList;
      } catch (SocketException ex) {}
      return null;
  }
  </code></pre>
  
  <p>The result is <code>[fe80::5054:ff:fe12:3456%eth0, 10.0.2.15]</code></p>
  
  <p>What do I have to configure or do to make the emulator reachable by my desktop programs?</p>
  
  <p>I have done the following:</p>
  
  <p><code>&gt; adb forward tcp:50000 tcp:50000</code></p>
  
  <p>However, I am unable to access the server through localhost:50000.</p>