MindBrain
MindBrain

Reputation: 7768

Connect Android app to server running on localhost

I would like to connect my android mobile app to a local server running on 127.0.0.1 so I can access the data from the API to retrieve customer data. How can I do so ? Error is throwing an error as below com.android.volley.NoConnectionError Failed to connect to 127.0.0.1/5000.

Upvotes: 2

Views: 4316

Answers (2)

BlueMeth
BlueMeth

Reputation: 1

Android studio's emulator's network is separate from your local machine.

So if you use 127.0.0.1, actually you're pointing to your emulator's loopback interface, not your local machine.

To make Android Studio connect to your local machine you need to set your API's Url to 10.0.2.2.

Also see: https://developer.android.com/studio/run/emulator-networking for more info.

Upvotes: 0

jeprubio
jeprubio

Reputation: 18002

You can connect to your machine using the 10.0.2.2 ip.

https://developer.android.com/studio/run/emulator-networking#networkaddresses

10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

Upvotes: 4

Related Questions