1

I have written an App in which i am connecting to localhost using System's IP Address via Emulator, but now i want to connect to LocalHost via Android Device

Problem is whenever i am trying to connect via App getting a problem, in short : Local Host not responding.....

I am using Wifi to connect localhost.. any help please....

Code:

 public void onClick(View v) {

                String url = "http://ipaddress/checkLogin.php";
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("strUser", txtUser.getText().toString()));
                params.add(new BasicNameValuePair("strPass", txtPass.getText().toString()));
                String resultServer  = getHttpPost(url,params);
                Log.d("Entire string::", " "+resultServer);
1

2 Answers 2

2

Don't use Wifi to connect via Android Device, always use USB to connect LocalHost via Device or place your files and make database using online server...

and nothing wrong with your code:

 public void onClick(View v) {

            String url = "http://ipaddress/checkLogin.php";
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("strUser", txtUser.getText().toString()));
            params.add(new BasicNameValuePair("strPass", txtPass.getText().toString()));
            String resultServer  = getHttpPost(url,params);
            Log.d("Entire string::", " "+resultServer);
Sign up to request clarification or add additional context in comments.

2 Comments

welcome to SO and thanks to help, i guess you can also help me here: stackoverflow.com/questions/15984338/…
-1 for perpetuating the misuse of the word "localhost" to refer to anything other than the machine (real or emulated) on which the client software itself is running.
1

USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.

C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf

onlineoffline tag - don't remove
    Order Deny,Allow
    Allow from all // change it Allow
    Allow from 127.0.0.1

2 Comments

10.0.2.2 only works for emulators, it does not work for physical devices.
Chris what is the way to do it on the device?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.