What is the exact difference between "Connect timed out" and "failed to connect to" in java.net.SocketTimeoutException?

Viewed 358

In my log, I could find two SocketTimeoutException.

1. SocketTimeoutException: connect timed out

Caused by: java.net.SocketTimeoutException: Connection timed out  
at java.net.PlainSocketImpl.socketConnect(Native Method)    
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) 
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)  
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)   
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)   
at java.net.Socket.connect(Socket.java:589) 
...

2. SocketTimeoutException: failed to connect to..

java.net.SocketTimeoutException: failed to connect to somedomain.com/123.123.123.44 (port 80) after 30000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:169)
at libcore.io.IoBridge.connect(IoBridge.java:122)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
at java.net.Socket.connect(Socket.java:882)
...

What are the differences between connect timed out and failed to connect to ?

1 Answers

The words mean the same thing, so my take is that the exceptions are indicating the same thing.

The different messages are due to two different socket implementations being used.

  • The first case is using the standard Java plain (non-SSL) socket implementation; i.e. the default one on Java SE.

  • The second case is using the IOBridge implementation that is used on Android.

It seems that some of your logs are coming from Android devices.

Related