title: Getting a list of servers listening on a specific port in android
body: <p>I'm developing an android app which is used to remote control PC from an android phone. I managed to develop a fully functional app (client and server(java) app) except i have to specify for the client on which IP to connect. Both client and server are opening a socket and listening on port 8998. Is there a way of getting a list of servers (on client side) listening on that specific port?</p>
  
  <p>Thank you in advance,</p>
  
  <p>Kristian </p>
  
  <pre><code>    try {
  
          InetAddress serverAddress = InetAddress.getByName(Constants.SERVER_IP); // getting the inet adress of the server
          NetworkInterface netInterface = NetworkInterface.getByInetAddress(serverAddress); // getting the interface name where all other servers should be
          Enumeration&lt;InetAddress&gt; addresses = netInterface.getInetAddresses();
  
          for (InetAddress inetAddress : Collections.list(addresses)) {
  
              out.println("InetAddress: " +  inetAddress);
              Log.d("adresses", String.valueOf(inetAddress));
          }
  
      }catch(IOException e){
          Log.e("err", "Unknown hostname!");
      }
  </code></pre>