简体   繁体   中英

When using Android sockets, why would a connection be “actively refused”?

I've copy/pasted the code from this tutorial about sockets on Android .

It builds fine and runs as expected, until a connection is attempted.

I've got it connected with USB and I've used ADB to turn on port forwarding.

I've written test apps in C# (which I'm more comfortable with than Java) and I keep getting error 10061 :

No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.

When I use SocketTest , I get the following (rather cryptic) message:

Connection error: connect

I've tried disabling my firewall, but this doesn't help. What could be wrong?

"Actively refused" means that the target has send an packet back signaling that there is no process listening on the port ("no server application running"). Some firewalls even filter these packets, resulting in an timeout when there is an connection attempt.

It turns out it was to do with ADB. I had started port forwarding at the beginning of my session, but the ADB process must have restarted at some point because when I reissued the port forward command my app sprang to life.

Real pity there's no way of viewing the ports currently being forwarded by ADB. I suppose the bottom line is "if in doubt, do it again".

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