sockets – java.net.SocketException: Network is unreachable: connect

sockets – java.net.SocketException: Network is unreachable: connect

You are facing a connection breakdown. Does this happen in 3G, WiFi or plain connection on a computer?

Anyway, you must assume that the connection may be lost from time to time, when writing your app. For example, with mobiles, this happens frequently in the tube, in basements, etc. With PC apps, this is less frequent but occurs sometimes.

A retry can be a good solution. And a clean error message that explains the network is not available at this moment too.

Network is unreachable means just that. Youre not connected to a network. Its something outside of your program. Could be a bad OS setting, NIC, router, etc.

sockets – java.net.SocketException: Network is unreachable: connect

I faced situation of getting java.net.SocketException not sometimes but every time. Ive added -Djava.net.preferIPv4Stack=true to java command line and my program started to work properly.

Leave a Reply

Your email address will not be published. Required fields are marked *