Module java.base
Package java.net

Class Socket

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

public class Socket extends Object implements Closeable
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 the SocketImpl class.

The Socket class defines convenience methods to set and get several socket options. This class also defines the setOption and getOption methods to set and query socket options. A Socket support the following options:

Socket options
Option Name Description
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: