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 ;)
– Carlos Bridi
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..
– Gustavo S.
You added permission in the external connection manifest.xml?
– Carlos Bridi
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
– Gustavo S.
http://stackoverflow.com/questions/9922543/why-does-inetaddress-isreachable-return-false-when-i-can-ping-the-ip-address
– Carlos Bridi
http://stackoverflow.com/questions/4779367/problem-with-isreachable-in-inetaddress-class
– Carlos Bridi
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
– Gustavo S.
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4921816
– Carlos Bridi
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 ;)
– Carlos Bridi
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..
– Gustavo S.