Android app without connection to valid IP addresses

Asked

Viewed 40 times

1

I am having a very strange problem with my android application, in certain cases my application can not answer valid addresses from other locations. Explaining my application, is a field data collection application, 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 can not, I have done several tests with various addresses, some the application can answer and others not. Follow 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 validate the address, as this in the first line of this code.

  • Post the printStackTrace ;)

  • But the " isReacable() " method does not launch Exception.. he is just that if, Try in there is to see if, after being able to check if the ip of the remote server is accessible, check if it can connect to the socket server..

  • You added permission in the external connection manifest.xml?

  • Yes, the detail is that some Ips respond and others do not, including tested with valid Ips from google itself and returns me false in this validation :s

  • http://stackoverflow.com/questions/9922543/why-does-inetaddress-isreachable-return-false-when-i-can-ping-the-ip-address

  • http://stackoverflow.com/questions/4779367/problem-with-isreachable-in-inetaddress-class

  • Dude, this almost hehe, it seems like it’s even this isReachable() method that doesn’t always return true.. now I have to see only one alternative

  • http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4921816

  • If you want to test if the site is in the air or giving answer, can shoot once against the site and see the response of html...if you give 200, It was good ;)

  • Actually I have a server socket running on each client, I think I’ll just test the socket connection and let go of the ping... I think I’ve solved my problem.. Just to clarify, I have to do this test because, the user can synchronize the data both being on the local network, and outside the company using 3g..

Show 5 more comments

1 answer

0

Solved, the problem is in the isReachable() method, it does not return me guaranteed if the destination is accessible, so I changed my logic to just validate the connection directly with my server socket, in this way:

                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 = "";
                } 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.