0

Im developing a native android app , there are no errors but Logcat says

  Caused by: java.net.ConnectException: failed to connect to some ip.
  Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT 

The warning line pointed by android - Studio :-

 HttpResponse httpResponse = httpClient.execute(httpPost);

This issue occurs when your app is not able to communicate with your local server on LAN .

Can any one suggest me articles to handle this Exceptions efficently ? Just wanted my app to be free of errors and warnings .

May be we can use a try - catch ? Atleast , just to show a toast "Connection error" :)

Vikrant
  • 444
  • 1
  • 5
  • 22
  • refer here..http://stackoverflow.com/questions/32954067/java-net-connectexception-failed-to-connect-to-10-0-0-2-port-80-connect-fai and from this too http://stackoverflow.com/questions/20028648/client-socket-times-out-when-connecting-to-server – brahmy adigopula Sep 24 '16 at 12:12
  • Actually i had done some research earlier on this , gottcha ! – Vikrant Sep 24 '16 at 12:21

1 Answers1

0

Connectivity is one of those things that rely on various Real World™ coincidences, like being within range of a Wi-Fi hotspot, and your signal not being drowned by another Wi-Fi signal on the same channel. It is therefore guaranteed that at times, it will fail.

Since you say that "there are no errors", this means that the error is handled somewhere, somehow, perhaps in code that you have no control over. However, the fact that the error gets handled does not mean that there is no disruption in the communication. If you had a constant stream of data flowing between client and server, there would be a gap in the continuity of the data at that moment. The transmission may have been retried, and succeeded, but there was a delay. If you find delays, and you are troubleshooting them, you do want to know their cause. Therefore, these log messages are important.

So, you need to get used to them, and learn to ignore them until the time comes one day when you will be troubleshooting something connectivity related, at which point you will learn to also love them.

To conclude: "Connection error" toasts are not very helpful, because in a real-world usage scenario, they would be popping up all the time. Allowing the errors to be logged is probably the only thing you can do, and probably also the best.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142