Module java.base
Package java.net

Class Socket

java.lang.Object
java.net.Socket
All Implemented Interfaces:
Closeable,AutoCloseable
Direct Known Subclasses:
SSLSocket

public classSocketextendsObjectimplementsCloseable
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.

The actual work of the socket is performed by an instance of theSocketImpl class.

TheSocket class defines convenience methods to set and get several socket options. This class also defines thesetOption andgetOption methods to set and query socket options. ASocket support the following options:

Socket options
Option NameDescription
SO_SNDBUF The size of the socket send buffer
SO_RCVBUF The size of the socket receive buffer
SO_KEEPALIVE Keep connection alive
SO_REUSEADDR Re-use address
SO_LINGER Linger on close if data is present (when configured in blocking mode only)
TCP_NODELAY Disable the Nagle algorithm
Additional (implementation specific) options may also be supported.

Since:
1.0
See Also: