java.net · java.base · since Java 1.0

Socket

declaration
public class Socket implements Closeable

A 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.