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 9047267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:52:12+00:00 2026-06-16T11:52:12+00:00

I am trying to connect to a host in my local network. Reaching it

  • 0

I am trying to connect to a host in my local network. Reaching it works from my computer or my android phone (SGS2) and it seems it also works from withing my app, but I want to get a result to check if it worked and depending on that proceed with further actions.

I am using an implementation of ASyncTask, named Connector.
When I call Connector I don’t just call execute but also get() in order to receive a boolean value denoting the success. The problem here is that execute performs fine (the host is definitely reached and I land at my breakpoints in doInBackground.

But how can I receive the boolean value which I return in doInBackground?
When I call get() it never finishes…

Basically, what I care about is the variable “connected”, but get() seems to run perpetuously!
Permissions are granted in the manifest, wifi on my phone is enabled and works, I can reach the host.

This is where I execute Connector:

url = new URL("http://192.168.2.103/?LED=T");
            Connector connector = new Connector();
            AsyncTask<URL, Integer, Boolean> execute = connector
                    .execute(url);
            Status status = execute.getStatus();
            boolean connected = false;
            try {
                Log.d("MainActivity", "trying to get result");
                connected = connector.get();
                Log.d("MainActivity", "got result");
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            } catch (ExecutionException ee) {
                ee.printStackTrace();
            }
            System.out.println();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        //do something depending on connected

And this is Connector:

public class Connector extends AsyncTask<URL, Integer, Boolean> {

public static boolean connect(URL url) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url.toString());
    System.out.println();

    try {
        HttpResponse response = httpclient.execute(httppost);
        int statusCode = response.getStatusLine().getStatusCode();
        Log.d("myapp", "response " + response.getEntity());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

@Override
protected Boolean doInBackground(URL... params) {
    boolean connect = connect(params[0]);

    return connect;
}

@Override
protected void onPostExecute(Boolean result) {
    Log.d("Connector", "onPostExecute");
    super.onPostExecute(result);
}

}

  • 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-06-16T11:52:13+00:00Added an answer on June 16, 2026 at 11:52 am

    I don’t think you want to call get() since you have already run the AsyncTask with execute(). If you just want to see that the connected variable is being set then use a Lof in your onPostExecute() since the result from doInBackground is sent to it. If you need to do something with it then you can do that in onPostExecute() as well

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

Sidebar

Related Questions

I'm trying to connect to a remote host(CentOS) mysql database from localhost(CentOS) with phpmyadmin
I am trying to connect to a local host sql server 2008 express server.
I'm trying to connect to an SMTP server from my local machine (127.0.0.1). I'm
I am trying to connect to a remote MySql server from my local machine.
I'm trying to connect from a host (PC or other) to a mobile cellular
Iam trying to connect my android device with a bluetooth compatible device. I know
Im trying to connect MySql from VB.NET in visual basic 2010. I wanted to
i'm trying to connect to a database building a class connection()saved in local folder
I'm trying to connect to Paypal Sandbox from a new server. If I test
I have installation of magento 1.6.1 on local machine i\’m trying to connect magetno\’s

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.