Android connection server exception

Android connection server exception

abnormal

Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) from /127.0.0.1 (port 53568) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
W/System.err: at libcore.io.IoBridge.isConnected(IoBridge.java:334)
insert image description here

Problem Description

I wrote an Android project, the android project runs on Android Studio, the server code runs on the idea, and the two run on a computer. I request the server data through http in the Android project and throw the above exception. But requesting Baidu's url can return data normally.

reason

Baidu: http://www.baidu.com
Own server: http://localhost:8080/test/f01

Comparing Baidu's url with your own url, after a little thought, you can conclude that there is a problem with the ip. Because our Android project runs on the android virtual machine, whether we use localhost or 127.0.0.1 here, we are looking for it in that virtual machine, but there is no server code in the virtual machine.

(Your localhost and 127.0.0.1 want to represent your computer, but when the android project runs in a virtual machine, it represents a virtual machine)
insert image description here

Solution
Check the ip of the wireless network card under cmd, and replace the ip of the url with this
http://192.168.3.245:8080/test/f01
insert image description here
Principle: The virtual machine can find your server through the wireless network ip of your computer through the Internet access function.

Guess you like

Origin blog.csdn.net/baiqi123456/article/details/129284305