Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:49:55+00:00 2026-05-20T10:49:55+00:00

I’m currently writing a small test Android app, and have run across a small

  • 0

I’m currently writing a small test Android app, and have run across a small (large) problem with the emulator.

The code that goes out and scans the local subnet for computers running my server piece of the software does not return anything! This code functions perfectly on the desktop portion, so I know something is wrong inside of my emulator.

I had to hardcode the IP scan first because I cannot determine the IP address within the emulator, so I know I’m at least scanning the right range.

Summary: How can I connect to servers via sockets from inside my emulator on the local subnet?

Thanks all!

Here’s the requested code:

public static ArrayList<String> serviceScanner() {
    ArrayList<String> servers = new ArrayList<String>();

    // Get the IP of the local machine
    String iIPv4 = "";
    String test = "";


    //getLocalIpAddress();
    //System.out.println(test);

    try {
        // Get localhost
        InetAddress addr = InetAddress.getLocalHost();

        // Get IP Address
        byte[] ipAddr = addr.getAddress();

        iIPv4 = addr.toString();
        iIPv4 = iIPv4.substring(iIPv4.indexOf("/") + 1);
        iIPv4 = "10.0.2.1";
    } catch (UnknownHostException e) {
        // Exception output
    }
    // IP stuff.
    String IPv4Start = "", IPv4End = "";
    iIPv4 = iIPv4.substring(0, iIPv4.lastIndexOf("."));
    iIPv4 += ".";
    IPv4Start = iIPv4 + "1";
    IPv4End = iIPv4 + "254";


    PrintWriter out = null;
    BufferedReader in = null;

    // Loop to scan each address on the local subnet
    for (int i = 1; i < 255; i++) {

        try {
            System.out.println(iIPv4+i);
            Socket mySocket = new Socket();
            SocketAddress address = new InetSocketAddress(iIPv4 + i, port);

            mySocket.connect(address, 5);

            out = new PrintWriter(mySocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(
                    mySocket.getInputStream()));
            out.println("Scanning!");
            String fromServer;
            while ((fromServer = in.readLine()) != null) {
                System.out.println("Server: " + fromServer);
                if (fromServer.equals("Server here!")) {
                    servers.add(iIPv4 + i);
                    mySocket.close();
                    break;
                }
            }
            mySocket.close();
            out.close();
            in.close();

        } catch (UnknownHostException e) {
        } catch (IOException e) {
        }
    }
    return servers;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:49:56+00:00Added an answer on May 20, 2026 at 10:49 am

    The emulator is not on the same subnet as your computer. It’s on it’s own virtual subnet connected to the computer via its own NAT router. There is an explanation here: http://developer.android.com/guide/developing/devices/emulator.html#emulatornetworking

    However, the emulator, via its router, should be able to connect to any socket anywhere on the Internet. What is the address you are trying to connect to? The emulator won’t route 10.0.0.0 private addresses because it uses them for itself. Not sure about 168.192.0.0. Can you post the code that is failing?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.