The SocketBackendHandler currently resolves the target hostname to a single IP address and connects there, either synchronously or asynchronously. Instead, look up all IP addresses for the hostname and try them in a loop. If none of the addresses responds, throw an exception and use Throwable.addSuppressed to attach the exceptions for all the failed attempts.
Note that this is a place where the students have to fill a gap, so the gap will have to be revised. Lookup code should be shared between the synchronous and asynchronous cases. Ideally, error handling code is shared as well. But some copy'n'paste from the asynchronous to the synchronous case is acceptable.
For testing the scenario, play around with /etc/hosts or the Windows equivalent. Define a hostname there, with some IP addresses pointing to wrong hosts or nowhere. Use debug output to verify that connection attempts fail before the correct host is contacted.
The
SocketBackendHandler
currently resolves the target hostname to a single IP address and connects there, either synchronously or asynchronously. Instead, look up all IP addresses for the hostname and try them in a loop. If none of the addresses responds, throw an exception and useThrowable.addSuppressed
to attach the exceptions for all the failed attempts.Note that this is a place where the students have to fill a gap, so the gap will have to be revised. Lookup code should be shared between the synchronous and asynchronous cases. Ideally, error handling code is shared as well. But some copy'n'paste from the asynchronous to the synchronous case is acceptable.
For testing the scenario, play around with
/etc/hosts
or the Windows equivalent. Define a hostname there, with some IP addresses pointing to wrong hosts or nowhere. Use debug output to verify that connection attempts fail before the correct host is contacted.