2

I have a simple application where I open a TCP socket connection to a server and then send some data over it. It works fine but I am getting the following exception on Nexus 5X devices. Since I am able to connect to the server with other devices its not a issue on server side.

09:00:05.118+03:00 D/com.testing.android.util.Util getCurrentGatewayIP: 192.168.1.1
09:00:05.120+03:00 D/com.testing.android.util.TCPClient Connect()
09:00:05.121+03:00 D/com.testing.android.util.TCPClient openSocket
09:00:17.162+03:00 E/com.testing.android.util.TCPClient sendInfo
09:00:17.163+03:00 E/com.testing.android.util.TCPClient java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
    at java.net.Socket.connect(Socket.java:586)
    at com.testing.android.util.TCPClient.openSocket(TCPClient.java:208)
    at com.testing.android.util.TCPClient.connect(TCPClient.java:53)

    at android.os.AsyncTask$2.call(AsyncTask.java:304)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)

UPDATE:

It looks like Nexus 5X blocks access to the server (which is part of LAN and connects to the phone through wifi). This network does not have internet connectivity. On other android devices you will get a notification "Wifi has no Internet access - This network has no Internet access. Stay connected? (Yes/No)" but you will still be able to communicate within the LAN. On Nexus unless user has accepted that they want to stay connected to the network all communication is blocked.

Ubaier Bhat
  • 854
  • 13
  • 33
  • I have same error and after digging a while I realized that my phone apply firewall with AFWall+ app recently, lol – 林果皞 Sep 11 '17 at 07:46

2 Answers2

2

Right now there is no programatic solution for this problem. The user has to allow the network manually. Since this is a security feature for detection of Captive Portals only system apps can disable this.

This post describes few more details

Community
  • 1
  • 1
Ubaier Bhat
  • 854
  • 13
  • 33
0

Connecting is implemented via native function connect(). man connect says:

ECONNREFUSED No-one listening on the remote address.

It means that you should check that your server is really available at specified address and port and is able to accept new connections.

Sergio
  • 8,099
  • 2
  • 26
  • 52