Android app without connection to valid IP addresses

1

I'm having a very strange problem with my android application, in some cases my application can not respond to valid addresses from other sites. Explaining my application, it is a data collection application in the field, where it connects with the client server to transfer the information remotely, via socket connection, the problem is that some clients my application can connect and others not, I did several tests with varied addresses, some the application gets answer and some do not. Here is the verification code:

if (InetAddress.getByName(sys.getNr_ipexterno()).isReachable(3000)) {
    ipAcessivel = sys.getNr_ipexterno();
    Log.d("IP" , sys.getNr_ipexterno() + " Responde");
    try {
        Socket socket = new Socket(ipAcessivel, 5555);
    } catch (IOException e) {
        e.printStackTrace();
        ipAcessivel = "";
    }
}

The problem is that my system can not even do the address validation, as it is in the first line of this code.

    
asked by anonymous 21.07.2016 / 14:12

1 answer

0

                ipAcessivel = sys.getNr_iplocal();
                try {
                    int timeoutMs = 2000;
                    SocketAddress sockaddr = new InetSocketAddress(ipAcessivel, 5555);
                    Socket sock = new Socket();

                    sock.connect(sockaddr, timeoutMs);

                    //Socket socket = new Socket(ipAcessivel, 5555);
                } catch (IOException e) {
                    e.printStackTrace();
                    ipAcessivel = "";
                } 
    
21.07.2016 / 18:24