2

I can connect to localhost:8080 when my android app connect to my project in wampserver with 10.0.0.2:8080,but i use laravel and my web service is in localhost:8000. i want to connect from emulator to my web service in laravel server in IP 10.0.0.2:8000 but i can't connect to it.

failed to connect to /10.0.2.2 (port 8000) after 10000 ms . i tried localhost:8000 and some other IP, which IP use to connect to laravel server?

2 Answers2

1

a bit late but your issue has to do with your routing. First of all assuming you are on windows go to your hosts file and map the IP: 10.0.2.2 to 127.0.0.1

Like so:

127.0.0.1    10.0.2.2

Then if you've configured your virtual hosts map the IP 10.0.2.2 to your project directory in your httpd-vhosts.conf

Like this:

<VirtualHost *:80>
    DocumentRoot "C:/www/example/"
    ServerName 10.0.0.2
    ServerAlias 10.0.0.2
</VirtualHost>
user3718908x100
  • 7,042
  • 14
  • 57
  • 115
  • Thank you but there is a point that should be mentioned. You should run command `php artisan serve --host=x`. x is the ip you get by running command `ipconfig` in windows and `ifconfig` in linux. And in emulator you should open `x:8000`. Anyway it worked partially. It just loads `favicon.ico` and `app.js`. @user3718908 – kodfire Jul 08 '20 at 05:46
  • Tried everything for Laravel 8 App on Apache2 virtualhost i.e. `php artisan serve` with ip and normal hostname setup in `sites-available`. After trying this it worked! Thanks. Problem is if I work on website I have to reset everything in `hosts` and `.conf`. You know of a dual setup for virtualhost with same root directory? – Hmerman6006 Mar 16 '22 at 19:58
0

if you figured out this with remote server but are in difficulty to run this on local machine

1. start server as:

 php artisan serve --host 0.0.0.0

Now it can accept request from emulator

2. in android app assign to main url:

"http://192.168.0.106:8000/api"

you can get the url from ipconfig command in command prompt window

CodeToLife
  • 2,981
  • 2
  • 35
  • 25