public interface ISocket
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this socket.
|
void |
doSynchronousSSLHandshake(int timeout)
Performs a "read" on the SSLSocket without removing it from the input stream.
|
InetAddress |
getInetAddress()
Returns the address to which the socket is connected.
|
InputStream |
getInputStream()
Returns an input stream for this socket.
|
InetAddress |
getLocalAddress()
Gets the local address to which the socket is bound.
|
int |
getLocalPort()
Returns the local port number to which this socket is bound.
|
SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or
null if it is not bound yet. |
OutputStream |
getOutputStream()
Returns an output stream for this socket.
|
int |
getPort()
Returns the remote port number to which this socket is connected.
|
SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or
null if it is unconnected. |
int |
getSoTimeout()
Returns setting for SO_TIMEOUT.
|
SSLSocket |
getSSLSocket()
Gets the underlying SSLSocket.
|
boolean |
getTcpNoDelay()
Tests if TCP_NODELAY is enabled.
|
boolean |
isBound()
Returns the binding state of the socket.
|
boolean |
isClosed()
Returns the closed state of the socket.
|
boolean |
isConnected()
Returns the connection state of the socket.
|
boolean |
isInputShutdown()
Returns whether the read-half of the socket connection is closed.
|
boolean |
isOutputShutdown()
Returns whether the write-half of the socket connection is closed.
|
boolean |
isSSLSocket()
Checks if this is an SSL socket.
|
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in
milliseconds.
|
void |
setTcpNoDelay(boolean on)
Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
|
void |
shutdownInput()
Places the input stream for this socket at "end of stream".
|
void |
shutdownOutput()
Disables the output stream for this socket.
|
InetAddress getInetAddress()
If the socket was connected prior to being closed
,
then this method will continue to return the connected address
after the socket is closed.
null
if the socket is not connected.InetAddress getLocalAddress()
wildcard
address
if the socket is closed or not bound yet.int getPort()
If the socket was connected prior to being closed
,
then this method will continue to return the connected port number
after the socket is closed.
int getLocalPort()
If the socket was bound prior to being closed
,
then this method will continue to return the local port number
after the socket is closed.
SocketAddress getRemoteSocketAddress()
null
if it is unconnected.
If the socket was connected prior to being closed
,
then this method will continue to return the connected address
after the socket is closed.
SocketAddress
representing the remote endpoint of this
socket, or null
if it is not connected yet.SocketAddress getLocalSocketAddress()
null
if it is not bound yet.
If a socket bound to an endpoint represented by an
InetSocketAddress
is closed
,
then this method will continue to return an InetSocketAddress
after the socket is closed. In that case the returned
InetSocketAddress
's address is the
wildcard
address
and its port is the local port that it was bound to.
SocketAddress
representing the local endpoint of this
socket, or null
if it is not bound yet.InputStream getInputStream() throws IOException
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 IllegalBlockingModeException
.
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.
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()
OutputStream getOutputStream() throws IOException
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 IllegalBlockingModeException
.
Closing the returned OutputStream
will close the associated socket.
IOException
- if an I/O error occurs when creating the
output stream or if the socket is not connected.void setSoTimeout(int timeout) throws SocketException
timeout
- the specified timeout, in milliseconds.SocketException
- if there is an error
in the underlying protocol, such as a TCP error.int getSoTimeout() throws SocketException
SocketException
- if there is an error
in the underlying protocol, such as a TCP error.void setTcpNoDelay(boolean on) throws SocketException
on
- true
to enable TCP_NODELAY,
false
to disable.SocketException
- if there is an error
in the underlying protocol, such as a TCP error.getTcpNoDelay()
boolean getTcpNoDelay() throws SocketException
boolean
indicating whether or not TCP_NODELAY is enabled.SocketException
- if there is an error
in the underlying protocol, such as a TCP error.void close() throws IOException
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.
IOException
- if an I/O error occurs when closing this socket.void shutdownInput() throws IOException
If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.
IOException
- if an I/O error occurs when shutting down this
socket.void shutdownOutput() throws IOException
If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.
IOException
- if an I/O error occurs when shutting down this socket.boolean isConnected()
Note: Closing a socket doesn't clear its connection state, which means
this method will return true
for a closed socket
(see isClosed()
) if it was successfully connected prior
to being closed.
boolean isBound()
Note: Closing a socket doesn't clear its binding state, which means
this method will return true
for a closed socket
(see isClosed()
) if it was successfully bound prior
to being closed.
boolean isClosed()
boolean isInputShutdown()
boolean isOutputShutdown()
boolean isSSLSocket()
SSLSocket getSSLSocket()
void doSynchronousSSLHandshake(int timeout) throws IOException
timeout
- Time in milliseconds to complete the handshake.IOException
- In case of socket errors.Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.