Retrofit cannot connect to my local web server on port 3000

前端 未结 2 953
广开言路
广开言路 2020-12-15 17:30

My app that is using Retrofit (v1.6.1) to connect to REST web services cannot connect to my local web server (running on localhost), this is the error I am gett

相关标签:
2条回答
  • 2020-12-15 17:39

    On your phone connecting to localhost:3000 means "connect to port 3000 on local network interface" - which is local interface of the phone, not the port 3000 of the PC to which your phone is connected. There is nothing listening on port 3000 on the phone, so you get connection refused error.

    Whould you're trying to do is (probably, hard to guess without more information) is to connect from the phone to port 3000 on you PC. So you should change the address you're connecting to from localhost to address of the PC. In case of emulator that would be 10.0.2.2 (which is localhost of the PC). See networking information for reference.

    0 讨论(0)
  • 2020-12-15 17:45

    I solved the issue, need to use 10.0.2.2 instead of localhost to connect to my local server.

    Found it here - http://developer.android.com/tools/devices/emulator.html#networkaddresses

    0 讨论(0)
提交回复
热议问题