Lesson content
Read, practise, then check your understanding
Socket provides a TCP client endpoint; ServerSocket accepts connections. Protocols need message framing, encoding, size limits, timeouts, authentication, and clean shutdown.
Modern HTTP
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(3)).build();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.timeout(Duration.ofSeconds(5)).GET().build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
Validate status, content type, redirects, and response size. Async sending returns CompletableFuture. Bound retries with backoff and idempotency awareness. Treat remote input as untrusted, use TLS verification, avoid SSRF by constraining destinations, and close socket streams deterministically.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.