ECONNREFUSED - Cannot connect from Android Studio to a Node.js web app on the same PC - visual-studio

I am developing an app in Android Studio and it makes Http calls to a Node.js web application that I am developing in Visual Studio. All these are on the same Windows 10 PC now.
The Node.js web app is running via Visual Studio 2017 and listening at port 1337. I am able to connect to localhost:1337/ from both Chrome and Edge and verify that the Node.js app is running well. However, from the Android app running in an Android emulator, when trying to connect to localhost:1337/ it got:
Exception: failed to connect to localhost/127.0.0.1 (port 1337): connect failed: ECONNREFUSED (Connection refused)
I disabled the Windows Firewall, but the same problem is still there.
If I deploy the Node.js app to a real web site on AWS, the Android app in the emulator is able to connect to that and work as expected. The downside is that I am unable to step through the Node.js app to debug.
So, on its own, the Node.js app is running fine on my PC and browsers can connect to it. On its own, the Android app is running fine on my PC, and able to connect to the Node.js app on the Internet. The problem is the Android app cannot talk to the Node.js app on the same PC.
Does the problem lie in Visual Studio, Windows or Android Studio?

As said before: localhost (127.0.0.1) is your emulator not your local computer.
check this.
How to connect to my http://localhost web server from Android Emulator in Eclipse
so use either the IP address of your computer or 10.0.2.2, which is a special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

I think , localhost didn't work from android studio, because from emulator android studio you cannot direct access
you might be use 10.0.2.2 or 10.0.3.2 , may be this can help you
:)

Use your PC IP address. Run ifconfig/ipconfig in terminal/command prompt and look for something like an inet (or whatever looks like an IP address)

Right click on windows icon at extreme bottom left and select windows-shell or cmd and type ipconfig->enter. As it is the same conputer that Node.js is running, use the ipV4 address of ethernet adapter shown, instead of localhost in your app. Hope this helps...

Related

How to debug a Xamarin iOS app hitting a localhost asp.net core API

I have a Xamarin Forms app (Android and iOS, not UWP) that hits a DotNetCore 2.1 API I have created (runs under http://localhost:5000). All this is being developed using Visual Studio 2017.
I am able to debug the Android side with the address http://10.0.2.2:5000 which translates to 'localhost' on the Android side of things. So I am able to hit my API just fine from the Android simulator.
The problem is on the iOS side.
The iOS simulator is really running on the Mac, and thusly is not able to see my Windows machine running the API.
How do I configure my Windows/Mac machines so I am able to hit my local API?
I am able to ping my Windows machine from the Mac, but that's about it at this point.
I have this solved and am posting what I did to help others. I am now able to hit my .net core 2.1 web api from both the Android emulator, iOS emulator, and actual devices.
1) Run ipconfig to get your local IP address.
2) I didn't do anything special with the Program class. You can see this is the default File/New Project templated code. I saw many suggestions to use a more explicit Kestral configuration. I am sure in some scenarios it would help, but in my case this was not necessary.
3) Configure Kestral to listen on that IP and port (vs. localhost).
4) Open the firewall to pass traffic on that port.
netsh advfirewall firewall add rule name="Http Port 5000" dir=in action=allow protocol=TCP localport=5000

Windows phone emulator to access localhost web service

I have a webservice that I am running on a localhost (seperate project with .asmx file), and then I have a Xamarin UWP phone app that takes an input of a product code and returns certain information about it from the web service.
When I run the app in simulator mode it can connect to the local host however when I run it on a windows 10 phone emulator through visual studio it cannot connect to local host. This is a problem as I need to take screenshots of the app working in the Phone emulator.
Can anyone off suggestions to solve this please.

Xamarin Mac Agent Connection issue

I am new to Xamarin, I am having problems connecting from my windows 10 PC to my mac mini. If I disable Windows firewall I can connect but I don't want to leave my firewall turned off. Anyone know what port needs to be opened on the windows machine for the mac agent to communicate with? I tried opening SSH (Port 22), but that didn't help.
Xamarin Firewall Configuration Instructions
Xamarin Mac Agent
To connect Visual Studio to your Mac build host using the Xamarin Mac Agent requires the SSH port to be open. By default this is Port 22.

Windows Mobile device not connecting to VS2008 using CoreCon/RDB2008

I am trying to connect a Windows Mobile 5.0 device with Visual Studio 2008 using Corecon (tried all processor architecture files available inside wce400 folder) and RDB2008, but it won't connect. Here is the device details page:
Does anyone have any idea what could be wrong here? I suspect a mix-up of Device OS, architecture and SDK. Appreciate any effort or help on this. Thanks.
Remote debug within VS2008 for a Windows Mobile device needs a valid IP connection with the debug ports (5655) opened (if a firewall is active).
First try to start a debug session with a simple .NET Compact Framework application (a C# SmartDevice project) and the device is connected via USB ActiveSync/WindowsMobileDeviceCenter. If that does not work, you are in trouble. Does the device connect to Windows Mobile Device Center? Try Start>Settings>Connections>USBtoPC setting change on the device.
If you can 'debug' using an USB connection but not using WiFi, check subnet and ports and Internet connection setting for Wireless Card on the device. Can you ping the device from the VS2008 PC? Can you ping the VS2008 PC from the device (vxUtils ping)? Is the debug port opened on the device after RDB2008.exe started and installed (see my NetStat for Windows Mobile)?
You may try a network trace on the VS2008 PC to see what happens on port 5655. Or even a network trace on the device (MS powertoys NetAnalyze).
I assume you followed this

Can't find Xamarin Build Host

I installed Xamarin platform on my mac. But I can't find the Xamarin build host that and connect it to the Visual Studio on my PC. Does anyone know how to get it?
You have to configure you Mac for remote access: https://developer.xamarin.com/guides/ios/getting_started/installation/windows/#Configuration
The new buildhost is using ssh. It is using UDP broadcasts (mDNS, a.k.a. Bonjour) for advertising itself. In some networks/routers/switches UDP broadcasts are blocked. If you still can't find it, try to use the static ip of your mac.

Resources