Search code examples
androidruby-on-railsreact-nativelocalhostgenymotion

How to connect Rails server to Android emulator (Genymotion)


My current setup is Rails on the backend, React Native on the front end. According to other questions, I know that I need to use the address 10.0.3.2 to access localhost from within Genymotion (10.0.2.2 if you're on the default Android emulator).

How do I allow incoming connections for my Rails server?


Solution

  • In order to do this, follow these steps:

    1. By default, your Rails server does not accept connections outside of your local machine (remember that the emulator is independent from your computer when it comes to networking). So you need to bind your server to 0.0.0.0 to accept connections from anywhere:

    rails s --binding=0.0.0.0

    1. To test that the previous setup is working, go to your browser in your emulator and type in 10.0.3.2:3000. You should see the equivalent of typing localhost:3000 in your browser in your computer.