Reputation: 93
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:
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
Upvotes: 0
Views: 3201
Reputation: 437
After connecting with Wifi
Upvotes: 0
Reputation: 337
I work with PostgreSQL (Database) and Fedora 21 (Linux), for connection to db use jdbc driver.
This work for me:
- Connect android device to PC
- Connect your PC to hotspot (Phone wifi)
- Find ip address of PC by
ip addr
(see wifi connectionwlp3s0
ipnet
)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");
I work with PostgreSQL because that need to change pg_hba.conf file. host all all PC ip address/* [trust/md5]
In postgresql.conf
listen_addresses = '*'
port = 5432
- restart PostgreSQL.
- stop PC firewall (in my case is
systemctl stop firewall.service
)- It must work, enjoy.
Upvotes: 0
Reputation: 1935
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
Upvotes: 0
Reputation:
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.
Upvotes: 0