The most common errors that can be returned when a connection fails are:
ETIMEDOUT
After failing to establish a connection during a period of time,
the system decided there was no point in retrying any more.
The cause for this error is usually that the remote host
is down or that problems in the network resulted in transmissions
being lost.
ECONNREFUSED
The host refused service for some reason.
This error is usually caused by a server
process not being present at the requested host.
ENETDOWN
EHOSTDOWN
Status information received by the client host from the
underlying communication services indicates the net or the remote
host is down.
ENETUNREACH
EHOSTUNREACH
These operational errors can occur either because the network or
host is unknown (no route to the host or network is present) or
because status information to that effect has been delivered to
the client host by the underlying communication services.
If a connection fails at any time, the socket cannot be re-used;
it must be closed and a new socket created.