Failed to connect to local IP from Android application

The client failed to establish a connection to the local address localhost:3000.

The error encountered was:

dial tcp [::1]:3000: connectex: No connection could be made because the target machine actively refused it.

How can I solve it?

2 Answers

  1. Change your localhost:3000 address to local IP address for example 192.168.1.15:3000 etc.
  2. Your server and client must be in same network

Emulator

On an emulator the localhost is accessible using the IP 10.0.2.2 .
So localhost:3000 will be 10.0.2.2:3000 in your emulator.

Physical device

First of all you must be on the same network to be able to connect.

  • Get the PC ip using ipconfig (windows) and ip a or ifconfig (linux)
  • Connect to the PC localhost using it’s ip. i.g 192.168.2.121:3000
    (your firewall must be OK with this)

If you are trying to connect using code, same things are needed for this

Archive from: https://stackoverflow.com/questions/59044702/failed-to-connect-to-local-ip-from-android-application

Share

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *