Top Description Fields Constructors Methods
sun.security.ssl

pack-priv abstract Class BaseSSLSocketImpl

extends SSLSocket
Class Inheritance
Known Direct Subclasses
sun.security.ssl.SSLSocketImpl
Imports
java.io.*, java.net.*, java.nio.channels.SocketChannel, java.util.Set, javax.net.ssl.*

Abstract base class for SSLSocketImpl. Its purpose is to house code with no SSL related logic (or no logic at all). This makes SSLSocketImpl shorter and easier to read. It contains a few constants and static methods plus overridden java.net.Socket methods. Methods are defined final to ensure that they are not accidentally overridden in SSLSocketImpl. There used to be a finalize() implementation that sent close_notify's, but decided that was not needed. Not closing properly is more properly an error condition that should be avoided. Applications should close sockets and not rely on garbage collection. The underlying native resources are handled by the Socket Cleaner.
See Also
javax.net.ssl.SSLSocket, SSLSocketImpl

Field Summary

Modifier and TypeField and Description
private final InputStream
private static final String
PROP_NAME

TLS requires that a close_notify warning alert is sent before the connection is closed in order to avoid truncation attacks.

pack-priv static final boolean
private final Socket

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
bind(SocketAddress
the SocketAddress to bind to
bindpoint
)

Overrides java.net.Socket.bind.

Binds the address to the socket.

public void
close()

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Closes this socket.

public final void
connect(SocketAddress
the SocketAddress
endpoint
)

Overrides java.net.Socket.connect.

Connects this socket to the server.

public final SocketChannel
getChannel()

Overrides java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.

public final InetAddress
getInetAddress()

Overrides java.net.Socket.getInetAddress.

Returns the address of the remote peer for this connection.

public InputStream
getInputStream()

Overrides java.net.Socket.getInputStream.

Returns an input stream for this socket.

public final boolean
getKeepAlive()

Overrides java.net.Socket.getKeepAlive.

Tests if SO_KEEPALIVE is enabled.

public final InetAddress

Returns:

the local address to which the socket is bound.
getLocalAddress
()

Overrides java.net.Socket.getLocalAddress.

Gets the local address to which the socket is bound.

public final int
getLocalPort()

Overrides java.net.Socket.getLocalPort.

Returns the number of the local port that this connection uses.

public SocketAddress
getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Returns the address of the endpoint this socket is connected to

public final boolean
getOOBInline()

Overrides java.net.Socket.getOOBInline.

Tests if OOBINLINE is enabled.

public <T> T
getOption(SocketOption<T>
The socket option
name
)

Overrides java.net.Socket.getOption.

Returns the value of a socket option.

public OutputStream
getOutputStream()

Overrides java.net.Socket.getOutputStream.

Returns an output stream for this socket.

public final int
getPort()

Overrides java.net.Socket.getPort.

Returns the number of the remote port that this connection uses.

public final int
getReceiveBufferSize()

Overrides java.net.Socket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.

public SocketAddress
getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to

public final boolean
getReuseAddress()

Overrides java.net.Socket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

public final int
getSendBufferSize()

Overrides java.net.Socket.getSendBufferSize.

Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

public final int
getSoLinger()

Overrides java.net.Socket.getSoLinger.

Returns the socket's linger timeout.

public final int
getSoTimeout()

Overrides java.net.Socket.getSoTimeout.

Returns the socket timeout.

public final boolean
getTcpNoDelay()

Overrides java.net.Socket.getTcpNoDelay.

Returns true if the Nagle optimization is disabled.

public final int
getTrafficClass()

Overrides java.net.Socket.getTrafficClass.

Gets traffic class or type-of-service in the IP header for packets sent from this Socket.

public final boolean
isBound()

Overrides java.net.Socket.isBound.

Returns the binding state of the socket.

public final boolean
isConnected()

Overrides java.net.Socket.isConnected.

Returns the connection state of the socket.

public boolean
isInputShutdown()

Overrides java.net.Socket.isInputShutdown.

Returns the input state of the socket

pack-priv boolean
public boolean
isOutputShutdown()

Overrides java.net.Socket.isOutputShutdown.

Returns the output state of the socket

public final void
sendUrgentData(int
The byte of data to send
data
)

Overrides java.net.Socket.sendUrgentData.

Send one byte of urgent data on the socket.

public final void
setKeepAlive(boolean
whether or not to have socket keep alive turned on.
on
)

Overrides java.net.Socket.setKeepAlive.

Enable/disable SO_KEEPALIVE.

public final void
setOOBInline(boolean
true to enable SO_OOBINLINE, false to disable.
on
)

Overrides java.net.Socket.setOOBInline.

Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.

public <T> Socket
setOption(SocketOption<T>
The socket option
name
,
T
The value of the socket option. A value of null may be valid for some options.
value
)

Overrides java.net.Socket.setOption.

Sets the value of a socket option.

public void
setPerformancePreferences(int
An int expressing the relative importance of a short connection time
connectionTime
,
int
An int expressing the relative importance of low latency
latency
,
int
An int expressing the relative importance of high bandwidth
bandwidth
)

Overrides java.net.Socket.setPerformancePreferences.

Sets performance preferences for this socket.

public final void
setReceiveBufferSize(int
the size to which to set the receive buffer size. This value must be greater than 0.
size
)

Overrides java.net.Socket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this Socket.

public final void
setReuseAddress(boolean
whether to enable or disable the socket option
on
)

Overrides java.net.Socket.setReuseAddress.

Enable/disable SO_REUSEADDR.

public final void
setSendBufferSize(int
the size to which to set the send buffer size. This value must be greater than 0.
size
)

Overrides java.net.Socket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this Socket.

public final void
setSoLinger(boolean
whether or not to linger on.
flag
,
int
how long to linger for, if on is true.
linger
)

Overrides java.net.Socket.setSoLinger.

Assigns the socket's linger timeout.

public void
setSoTimeout(int
the specified timeout, in milliseconds.
timeout
)

Overrides java.net.Socket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

public final void
setTcpNoDelay(boolean
true to enable TCP_NODELAY, false to disable.
value
)

Overrides java.net.Socket.setTcpNoDelay.

Enables or disables the Nagle optimization.

public final void
setTrafficClass(int
an int value for the bitset.
tc
)

Overrides java.net.Socket.setTrafficClass.

Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.

public void
shutdownInput()

Overrides java.net.Socket.shutdownInput.

Places the input stream for this socket at "end of stream".

public void
shutdownOutput()

Overrides java.net.Socket.shutdownOutput.

Disables the output stream for this socket.

public Set<SocketOption<?>>
supportedOptions()

Overrides java.net.Socket.supportedOptions.

Returns a set of the socket options supported by this socket.

public String
toString()

Overrides java.net.Socket.toString.

Converts this socket to a String.

Inherited from javax.net.ssl.SSLSocket:
addHandshakeCompletedListenergetApplicationProtocolgetEnabledCipherSuitesgetEnabledProtocolsgetEnableSessionCreationgetHandshakeApplicationProtocolgetHandshakeApplicationProtocolSelectorgetHandshakeSessiongetNeedClientAuthgetSessiongetSSLParametersgetSupportedCipherSuitesgetSupportedProtocolsgetUseClientModegetWantClientAuthremoveHandshakeCompletedListenersetEnabledCipherSuitessetEnabledProtocolssetEnableSessionCreationsetHandshakeApplicationProtocolSelectorsetNeedClientAuthsetSSLParameterssetUseClientModesetWantClientAuthstartHandshake

Field Detail

consumedInputback to summary
private final InputStream consumedInput
PROP_NAMEback to summary
private static final String PROP_NAME

TLS requires that a close_notify warning alert is sent before the connection is closed in order to avoid truncation attacks. Some implementations (MS IIS and others) don't do that. The property below controls whether we accept that or treat it as an error. The default is "false", i.e. tolerate the broken behavior.

requireCloseNotifyback to summary
pack-priv static final boolean requireCloseNotify
selfback to summary
private final Socket self

Constructor Detail

BaseSSLSocketImplback to summary
pack-priv BaseSSLSocketImpl()
BaseSSLSocketImplback to summary
pack-priv BaseSSLSocketImpl(Socket socket)
BaseSSLSocketImplback to summary
pack-priv BaseSSLSocketImpl(Socket socket, InputStream consumed)

Method Detail

bindback to summary
public void bind(SocketAddress bindpoint) throws IOException

Overrides java.net.Socket.bind.

Binds the address to the socket.

Parameters
bindpoint:SocketAddress

Doc from java.net.Socket.bind.

the SocketAddress to bind to

Annotations
@Override
Exceptions
IOException:

Doc from java.net.Socket.bind.

if the bind operation fails, or if the socket is already bound.

See Also
java.net.Socket#bind
closeback to summary
public void close() throws IOException

Overrides java.net.Socket.close.

Implements java.io.Closeable.close.

Doc from java.net.Socket.close.

Closes this socket.

Any thread currently blocked in an I/O operation upon this socket will throw a SocketException.

Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.

Closing this socket will also close the socket's InputStream and OutputStream.

If this socket has an associated channel then the channel is closed as well.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when closing this socket.
connectback to summary
public final void connect(SocketAddress endpoint) throws IOException

Overrides java.net.Socket.connect.

Connects this socket to the server. This method is either called on an unconnected SSLSocketImpl by the application, or it is called in the constructor of a regular SSLSocketImpl. If we are layering on top on another socket, then this method should not be called, because we assume that the underlying socket is already connected by the time it is passed to us.

Parameters
endpoint:SocketAddress

the SocketAddress

Annotations
@Override
Exceptions
IOException:
if an error occurs during the connection
getChannelback to summary
public final SocketChannel getChannel()

Overrides java.net.Socket.getChannel.

Returns the unique SocketChannel object associated with this socket, if any.

Returns:SocketChannel

Doc from java.net.Socket.getChannel.

the socket channel associated with this socket, or null if this socket was not created for a channel

Annotations
@Override
See Also
java.net.Socket#getChannel
getInetAddressback to summary
public final InetAddress getInetAddress()

Overrides java.net.Socket.getInetAddress.

Returns the address of the remote peer for this connection.

Returns:InetAddress

Doc from java.net.Socket.getInetAddress.

the remote IP address to which this socket is connected, or null if the socket is not connected.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides java.net.Socket.getInputStream.

Doc from java.net.Socket.getInputStream.

Returns an input stream for this socket.

If this socket has an associated channel then the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the input stream's read operations will throw an java.nio.channels.IllegalBlockingModeException.

Reading from the input stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread reading from the input stream will close the underlying channel and cause the read method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is reading from the input stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The read method will then throw SocketException with the interrupt status set.

Under abnormal conditions the underlying connection may be broken by the remote host or the network software (for example a connection reset in the case of TCP connections). When a broken connection is detected by the network software the following applies to the returned input stream :-

  • The network software may discard bytes that are buffered by the socket. Bytes that aren't discarded by the network software can be read using read.

  • If there are no bytes buffered on the socket, or all buffered bytes have been consumed by read, then all subsequent calls to read will throw an IOException.

  • If there are no bytes buffered on the socket, and the socket has not been closed using close, then available will return 0.

Closing the returned InputStream will close the associated socket.

Returns:InputStream

an input stream for reading bytes from this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the input stream, the socket is closed, the socket is not connected, or the socket input has been shutdown using shutdownInput()
getKeepAliveback to summary
public final boolean getKeepAlive() throws SocketException

Overrides java.net.Socket.getKeepAlive.

Tests if SO_KEEPALIVE is enabled.

Returns:boolean

Doc from java.net.Socket.getKeepAlive.

a boolean indicating whether or not SO_KEEPALIVE is enabled.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getKeepAlive.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getKeepAlive
getLocalAddressback to summary
public final InetAddress getLocalAddress()

Overrides java.net.Socket.getLocalAddress.

Gets the local address to which the socket is bound.

Returns:InetAddress

the local address to which the socket is bound.

Annotations
@Override
Since
1.1
getLocalPortback to summary
public final int getLocalPort()

Overrides java.net.Socket.getLocalPort.

Returns the number of the local port that this connection uses.

Returns:int

Doc from java.net.Socket.getLocalPort.

the local port number to which this socket is bound or -1 if the socket is not bound yet.

Annotations
@Override
getLocalSocketAddressback to summary
public SocketAddress getLocalSocketAddress()

Overrides java.net.Socket.getLocalSocketAddress.

Returns the address of the endpoint this socket is connected to

Returns:SocketAddress

Doc from java.net.Socket.getLocalSocketAddress.

a SocketAddress representing the local endpoint of this socket, or a SocketAddress representing the loopback address if denied by the security manager, or null if the socket is not bound yet.

Annotations
@Override
See Also
java.net.Socket#getLocalSocketAddress
getOOBInlineback to summary
public final boolean getOOBInline() throws SocketException

Overrides java.net.Socket.getOOBInline.

Tests if OOBINLINE is enabled.

Returns:boolean

Doc from java.net.Socket.getOOBInline.

a boolean indicating whether or not SO_OOBINLINE is enabled.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getOOBInline.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getOOBInline
getOptionback to summary
public <T> T getOption(SocketOption<T> name) throws IOException

Overrides java.net.Socket.getOption.

Doc from java.net.Socket.getOption.

Returns the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

Returns:T

The value of the socket option.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Overrides java.net.Socket.getOutputStream.

Doc from java.net.Socket.getOutputStream.

Returns an output stream for this socket.

If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the output stream's write operations will throw an java.nio.channels.IllegalBlockingModeException.

Writing to the output stream is interruptible in the following circumstances:

  1. The socket is associated with a SocketChannel. In that case, interrupting a thread writing to the output stream will close the underlying channel and cause the write method to throw ClosedByInterruptException with the interrupt status set.
  2. The socket uses the system-default socket implementation and a virtual thread is writing to the output stream. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. The write method will then throw SocketException with the interrupt status set.

Closing the returned OutputStream will close the associated socket.

Returns:OutputStream

an output stream for writing bytes to this socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when creating the output stream or if the socket is not connected.
getPortback to summary
public final int getPort()

Overrides java.net.Socket.getPort.

Returns the number of the remote port that this connection uses.

Returns:int

Doc from java.net.Socket.getPort.

the remote port number to which this socket is connected, or 0 if the socket is not connected yet.

Annotations
@Override
getReceiveBufferSizeback to summary
public final int getReceiveBufferSize() throws SocketException

Overrides java.net.Socket.getReceiveBufferSize.

Doc from java.net.Socket.getReceiveBufferSize.

Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.

Returns:int

the value of the SO_RCVBUF option for this Socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
getRemoteSocketAddressback to summary
public SocketAddress getRemoteSocketAddress()

Overrides java.net.Socket.getRemoteSocketAddress.

Returns the address of the endpoint this socket is connected to

Returns:SocketAddress

Doc from java.net.Socket.getRemoteSocketAddress.

a SocketAddress representing the remote endpoint of this socket, or null if it is not connected yet.

Annotations
@Override
See Also
java.net.Socket#getRemoteSocketAddress
getReuseAddressback to summary
public final boolean getReuseAddress() throws SocketException

Overrides java.net.Socket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

Returns:boolean

Doc from java.net.Socket.getReuseAddress.

a boolean indicating whether or not SO_REUSEADDR is enabled.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getReuseAddress.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getReuseAddress
getSendBufferSizeback to summary
public final int getSendBufferSize() throws SocketException

Overrides java.net.Socket.getSendBufferSize.

Doc from java.net.Socket.getSendBufferSize.

Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

Returns:int

the value of the SO_SNDBUF option for this Socket.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
getSoLingerback to summary
public final int getSoLinger() throws SocketException

Overrides java.net.Socket.getSoLinger.

Returns the socket's linger timeout.

Returns:int

Doc from java.net.Socket.getSoLinger.

the setting for SO_LINGER.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getSoLinger.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getSoLinger
getSoTimeoutback to summary
public final int getSoTimeout() throws SocketException

Overrides java.net.Socket.getSoTimeout.

Returns the socket timeout.

Returns:int

Doc from java.net.Socket.getSoTimeout.

the setting for SO_TIMEOUT

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getSoTimeout.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getSoTimeout
getTcpNoDelayback to summary
public final boolean getTcpNoDelay() throws SocketException

Overrides java.net.Socket.getTcpNoDelay.

Returns true if the Nagle optimization is disabled. This relates to low-level buffering of TCP traffic, delaying the traffic to promote better throughput.

Returns:boolean

Doc from java.net.Socket.getTcpNoDelay.

a boolean indicating whether or not TCP_NODELAY is enabled.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getTcpNoDelay.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#getTcpNoDelay
getTrafficClassback to summary
public final int getTrafficClass() throws SocketException

Overrides java.net.Socket.getTrafficClass.

Gets traffic class or type-of-service in the IP header for packets sent from this Socket.

Returns:int

Doc from java.net.Socket.getTrafficClass.

the traffic class or type-of-service already set

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.getTrafficClass.

if there is an error obtaining the traffic class or type-of-service value.

See Also
java.net.Socket#getTrafficClass
isBoundback to summary
public final boolean isBound()

Overrides java.net.Socket.isBound.

Returns the binding state of the socket.

Returns:boolean

Doc from java.net.Socket.isBound.

true if the socket was successfully bound to an address

Annotations
@Override
See Also
java.net.Socket#isBound
isConnectedback to summary
public final boolean isConnected()

Overrides java.net.Socket.isConnected.

Returns the connection state of the socket.

Returns:boolean

Doc from java.net.Socket.isConnected.

true if the socket was successfully connected to a server

Annotations
@Override
See Also
java.net.Socket#isConnected
isInputShutdownback to summary
public boolean isInputShutdown()

Overrides java.net.Socket.isInputShutdown.

Returns the input state of the socket

Returns:boolean

Doc from java.net.Socket.isInputShutdown.

true if the input of the socket has been shutdown

Annotations
@Override
See Also
java.net.Socket#isInputShutdown
isLayeredback to summary
pack-priv boolean isLayered()
isOutputShutdownback to summary
public boolean isOutputShutdown()

Overrides java.net.Socket.isOutputShutdown.

Returns the output state of the socket

Returns:boolean

Doc from java.net.Socket.isOutputShutdown.

true if the output of the socket has been shutdown

Annotations
@Override
See Also
java.net.Socket#isOutputShutdown
sendUrgentDataback to summary
public final void sendUrgentData(int data) throws SocketException

Overrides java.net.Socket.sendUrgentData.

Send one byte of urgent data on the socket.

Parameters
data:int

Doc from java.net.Socket.sendUrgentData.

The byte of data to send

Annotations
@Override
See Also
At this point, there seems to be no specific requirement to support this for an SSLSocket. An implementation can be provided if a need arises in the future.
setKeepAliveback to summary
public final void setKeepAlive(boolean on) throws SocketException

Overrides java.net.Socket.setKeepAlive.

Enable/disable SO_KEEPALIVE.

Parameters
on:boolean

Doc from java.net.Socket.setKeepAlive.

whether or not to have socket keep alive turned on.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setKeepAlive.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#setKeepAlive
setOOBInlineback to summary
public final void setOOBInline(boolean on) throws SocketException

Overrides java.net.Socket.setOOBInline.

Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.

Parameters
on:boolean

Doc from java.net.Socket.setOOBInline.

true to enable SO_OOBINLINE, false to disable.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setOOBInline.

if there is an error in the underlying protocol, such as a TCP error.

See Also
Setting OOBInline does not have any effect on SSLSocket, since currently we don't support sending urgent data.
setOptionback to summary
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException

Overrides java.net.Socket.setOption.

Doc from java.net.Socket.setOption.

Sets the value of a socket option.

Parameters
<T>
The type of the socket option value
name:SocketOption<T>

The socket option

value:T

The value of the socket option. A value of null may be valid for some options.

Returns:Socket

this Socket

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
setPerformancePreferencesback to summary
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)

Overrides java.net.Socket.setPerformancePreferences.

Sets performance preferences for this socket.

Parameters
connectionTime:int

Doc from java.net.Socket.setPerformancePreferences.

An int expressing the relative importance of a short connection time

latency:int

Doc from java.net.Socket.setPerformancePreferences.

An int expressing the relative importance of low latency

bandwidth:int

Doc from java.net.Socket.setPerformancePreferences.

An int expressing the relative importance of high bandwidth

Annotations
@Override
See Also
java.net.Socket#setPerformancePreferences(int, int, int)
setReceiveBufferSizeback to summary
public final void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.Socket.setReceiveBufferSize.

Doc from java.net.Socket.setReceiveBufferSize.

Sets the SO_RCVBUF option to the specified value for this Socket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.

Increasing the receive buffer size can increase the performance of network I/O for high-volume connection, while decreasing it can help reduce the backlog of incoming data.

Because SO_RCVBUF is a hint, applications that want to verify what size the buffers were set to should call getReceiveBufferSize().

The value of SO_RCVBUF is also used to set the TCP receive window that is advertised to the remote peer. Generally, the window size can be modified at any time when a socket is connected. However, if a receive window larger than 64K is required then this must be requested before the socket is connected to the remote peer. There are two cases to be aware of:

  1. For sockets accepted from a ServerSocket, this must be done by calling ServerSocket#setReceiveBufferSize(int) before the ServerSocket is bound to a local address.
  2. For client sockets, setReceiveBufferSize() must be called before connecting the socket to its remote peer.
Parameters
size:int

the size to which to set the receive buffer size. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
setReuseAddressback to summary
public final void setReuseAddress(boolean on) throws SocketException

Overrides java.net.Socket.setReuseAddress.

Enable/disable SO_REUSEADDR.

Parameters
on:boolean

Doc from java.net.Socket.setReuseAddress.

whether to enable or disable the socket option

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setReuseAddress.

if an error occurs enabling or disabling the SO_REUSEADDR socket option, or the socket is closed.

See Also
java.net.Socket#setReuseAddress
setSendBufferSizeback to summary
public final void setSendBufferSize(int size) throws SocketException

Overrides java.net.Socket.setSendBufferSize.

Doc from java.net.Socket.setSendBufferSize.

Sets the SO_SNDBUF option to the specified value for this Socket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to set the underlying network I/O buffers.

Because SO_SNDBUF is a hint, applications that want to verify what size the buffers were set to should call getSendBufferSize().

Parameters
size:int

the size to which to set the send buffer size. This value must be greater than 0.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error.
setSoLingerback to summary
public final void setSoLinger(boolean flag, int linger) throws SocketException

Overrides java.net.Socket.setSoLinger.

Assigns the socket's linger timeout.

Parameters
flag:boolean

Doc from java.net.Socket.setSoLinger.

whether or not to linger on.

linger:int

Doc from java.net.Socket.setSoLinger.

how long to linger for, if on is true.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setSoLinger.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#setSoLinger
setSoTimeoutback to summary
public void setSoTimeout(int timeout) throws SocketException

Overrides java.net.Socket.setSoTimeout.

Doc from java.net.Socket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Parameters
timeout:int

the specified timeout, in milliseconds.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error
setTcpNoDelayback to summary
public final void setTcpNoDelay(boolean value) throws SocketException

Overrides java.net.Socket.setTcpNoDelay.

Enables or disables the Nagle optimization.

Parameters
value:boolean

Doc from java.net.Socket.setTcpNoDelay.

true to enable TCP_NODELAY, false to disable.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setTcpNoDelay.

if there is an error in the underlying protocol, such as a TCP error.

See Also
java.net.Socket#setTcpNoDelay
setTrafficClassback to summary
public final void setTrafficClass(int tc) throws SocketException

Overrides java.net.Socket.setTrafficClass.

Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.

Parameters
tc:int

Doc from java.net.Socket.setTrafficClass.

an int value for the bitset.

Annotations
@Override
Exceptions
SocketException:

Doc from java.net.Socket.setTrafficClass.

if there is an error setting the traffic class or type-of-service

See Also
java.net.Socket#setTrafficClass
shutdownInputback to summary
public void shutdownInput() throws IOException

Overrides java.net.Socket.shutdownInput.

Places the input stream for this socket at "end of stream". Any data sent to the input stream side of the socket is acknowledged and then silently discarded.

Annotations
@Override
Exceptions
IOException:

Doc from java.net.Socket.shutdownInput.

if an I/O error occurs when shutting down this socket.

See Also
java.net.Socket#shutdownInput
shutdownOutputback to summary
public void shutdownOutput() throws IOException

Overrides java.net.Socket.shutdownOutput.

Disables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence.

Annotations
@Override
Exceptions
IOException:

Doc from java.net.Socket.shutdownOutput.

if an I/O error occurs when shutting down this socket.

See Also
java.net.Socket#shutdownOutput
supportedOptionsback to summary
public Set<SocketOption<?>> supportedOptions()

Overrides java.net.Socket.supportedOptions.

Doc from java.net.Socket.supportedOptions.

Returns a set of the socket options supported by this socket. This method will continue to return the set of options even after the socket has been closed.

Returns:Set<SocketOption<?>>

A set of the socket options supported by this socket. This set may be empty if the socket's SocketImpl cannot be created.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.net.Socket.toString.

Doc from java.net.Socket.toString.

Converts this socket to a String.

Returns:String

a string representation of this socket.

Annotations
@Override