简体   繁体   中英

Http Connection Refused on Android Device

I am having a problem to connect to the server via android application which is running on a device. I could manage to connect the server on a emulator, but on the device it gives http connection refused error.

07-08 09:53:27.125: W/System.err(8958): org.apache.http.conn.HttpHostConnectException: Connection to http://xx.xx.xx.xxx:8080 refused

I set up the server on a different laptop and the server is connected to university network wireless-ly and I am trying to connect to the server via the app on the device which is on the same network.

What I don't understand is that there is no problem to connect the server on the emulator on a different computer, it gives connection failure when I test it on the actual device.

I have googled for the matter, but they were usually related to ip address issues, such as localhost, 127.0.0.1 or 10.0.0.2. To me, it doesn't seem to be the same problem.

Please help me out!

Thanks in advance

Is that IP address accessible to outside world?

Just a guess: I think the IP address, you were using might have been reserved. It worked in emulator cause you were still in the network (probably in your office). As you came outside the network with your real device it didn't work.

Since you are running the application in the emulator, which is a virtual machine, localhost and 127.0.0.1 points to the emulator itself.

To access the network interface of your machine, you need to use the IP address 10.0.2.2 instead.

I had the same problem and my answer was the firewall that blocked all the requests from outside, you can simply resolve this by temporary turn off your firewall. Other dummy possible causes in that the connection is refused: - your phone is connected to a different wifi (possible you forgot to change the networks) - clean/rebuild project (not in your case) - Internet permission from manifest (not in your case) - wrong url request (localhost or 127.0.0.1 instead the real machine ip eg: 192.168.0.101)

if other people computer can open, your IP is banned from that page. only your IP can't open, because that page block your IP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM