0

I'm trying to connect to my laptop's localhost via my android device. There's enough information on how to do this online, but for some reason it's not working for me.

I tried:

  • Setting an inbound rule in my firewall to allow incoming traffic on port 80
  • Editing my httpd.conf file to allow from all instead of 127.0.0.1

My laptop and phone are both connected to my router via wifi.

When trying to connect, my browser on my phone tells me that that it can't load the page because it's taking too long.

Edit:

I'm using Wampserver on my laptop

user3165926
  • 93
  • 3
  • 9
  • 1
    you need to use a remote ip address i.e (192.168.0.1) – Anderson K Mar 04 '15 at 17:25
  • Only your laptop can connect to it's own "localhost" - that is the whole point. If you want something else to do so, you will need something like an SSH tunnel so that remote traffic appears as if it is coming from something local on that machine itself. Otherwise you need to set your server to listen on a remote interface, and address that properly. – Chris Stratton Mar 04 '15 at 18:41

4 Answers4

0

localhost or 127.0.0.1 won't work, because they only relate to the machine the server is running on, not any machine on the network.

You have to run ifconfig on your laptop and see which local ip your router registered it and use that one. Should be something like 192.168.Y.X - Y is usually 0 or 1, but depends on your router configuration.

So, to sum up: open terminal, run ifconfig if UNIX, ipconfig if windows and use the local IP displayed.

0

If you want to access a url on your local machine say: http://localhost/mywebsite.com you need to give 10.0.2.2 instead of the localhost from your android device to access it. So your url in android will be like: http://10.0.2.2/mywebsite.com I have done this to access my websites hosted in IIS from the emulator though haven't checked it for a device. You can check if it helps :) P.S: The links are as an example not actual links.

Edit: The above wont work from device only emulator. For the device check: https://stackoverflow.com/a/8950423/4282901

Community
  • 1
  • 1
Syed Osama Maruf
  • 1,895
  • 2
  • 20
  • 37
0

I work with PostgreSQL (Database) and Fedora 21 (Linux), for connection to db use jdbc driver.

This work for me:

  1. Connect android device to PC
  2. Connect your PC to hotspot (Phone wifi)
  3. Find ip address of PC by ip addr (see wifi connection wlp3s0 ipnet)
  4. Insert ip address to your code for example:

    Class.forName("org.postgresql.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:postgresql://ip address of PC:5432/dbname","username","pass");

  5. I work with PostgreSQL because that need to change pg_hba.conf file. host all all PC ip address/* [trust/md5]

  6. In postgresql.conf

    listen_addresses = '*'
    port = 5432
  1. restart PostgreSQL.
  2. stop PC firewall (in my case is systemctl stop firewall.service)
  3. It must work, enjoy.
Michael
  • 317
  • 6
  • 11
0

After connecting with Wifi

  • Click Win+R and write cmd
  • After open Command line write "ipconfig" find value rus-"IPv4-адрес" eng-"IPv4-address" " IPv4-адрес. . . . . . . . . . . . : 192.168.1.100" for me
  • Come from "other divice" "192.168.1.100:Your Port"