java.net · java.base · since Java 1.0
Socket
public class Socket implements CloseableA TCP client connection: connect, then read/write its streams. Production rule: connect and read timeouts on every socket, no exceptions.
Key methods
void connect(SocketAddress endpoint, int timeoutMs) | Bounded connection attempt. |
void setSoTimeout(int timeoutMs) | Bound each read — otherwise a silent peer hangs you forever. |
InputStream getInputStream() / OutputStream getOutputStream() | The byte streams. |