Add guide how to connect to any service hosted at localhost from real device connected through Visual Studio
See original GitHub issueDescription
For MAUI run on Windows, it is easy to access localhost, it’s simply localhost. For MAUI run on Android emulator, simply replace localhost with 10.0.2.2 This is from this guide: https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services and it works fine.
For SQL Server Express used from emulator there is a nice tutorial here which works (the most important part is to open TCP/IP connections in the server config) (however the new Microsoft.Sql.Data
client does not work on Android or works only for newer Android (depending on the version)):
https://www.youtube.com/watch?v=xNmIdFjXzl4
But for Android device which runs MAUI application attached via Visual Studio debugger? 10.0.2.2 doesn’t work.
How to please connect to a service hosted on localhost? Not only HTTP but also TDS or any other protocol.
There is no guide for Android device afaik. But testing must be done also on a real device!
Thank you.
Public API Changes
Add documentation on how to access localhost from Android device when running via Visual Studio (both Debug and Release).
Intended Use-Case
Simulating production environment with MAUI app,
Possible workaround
- to connect localhost to Android device, if these are on the same network, a temporary private IP can be exposed by localhost and ports with applications open. However this is not a robust solution and router can frequently change the private IP addresses assigned to devices (having a static private IP address in a network is not guaranteed)
VS bug #1745020
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:14 (5 by maintainers)
I think the point is that “10.0.2.2” doesn’t work when an Android device is used through USB debugging, not when an emulator is used. It seems that I have the same issue.
@janseris how is the Android device connected to the development machine? Is it via USB, WiFi, or something else? I wonder if this might affect the guidance?