Jimmy Hill
Jimmy Hill

Reputation: 216

Connect to Local Host via Android Device

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);

Upvotes: 1

Views: 4635

Answers (2)

Mahaveer Muttha
Mahaveer Muttha

Reputation: 1727

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

Upvotes: 1

JellyBean
JellyBean

Reputation: 60

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);

Upvotes: 2

Related Questions