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);
Jimmy Hill
  • 216
  • 2
  • 5
  • 15

2 Answers2

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);
JellyBean
  • 60
  • 4
  • welcome to SO and thanks to help, i guess you can also help me here: http://stackoverflow.com/questions/15984338/how-to-update-quantity-using-tap-on-item-in-a-listview – Jimmy Hill Apr 15 '13 at 07:15
  • -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. – Chris Stratton Jun 18 '13 at 15:39
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
Mahaveer Muttha
  • 1,727
  • 4
  • 21
  • 33