public interface Socket extends AutoCloseable
Modifier and Type | Method and Description |
---|---|
SocketAddress |
getLocalAddress()
Returns the local address to which the socket is bound.
|
SocketAddress |
getRemoteAddress()
Returns the remote address to which the socket is connected.
|
boolean |
isBlocking()
Returns whether every I/O operation on this channel will block until it completes.
|
int |
read(ByteBuffer dst)
Reads a sequence of bytes into the given buffer.
|
void |
setBlocking(boolean blocking)
Sets whether every I/O operation on this channel will block until it completes.
|
<T> void |
setOption(SocketOption<T> name,
T value)
Sets the value of the socket option (e.g.
|
void |
setPerformancePreferences(int connectionTime,
int latency,
int bandwidth)
Sets the performance preferences for this socket.
|
void |
waitRead(long timeout,
TimeUnit timeUnit)
Waits for read I/O operation to be ready.
|
void |
waitWrite(long timeout,
TimeUnit timeUnit)
Waits for write I/O operation to be ready.
|
void |
wakeupRead()
Causes the
waitRead(long, TimeUnit) operation that has not yet returned to return immediately. |
void |
wakeupWrite()
Causes the
waitWrite(long, TimeUnit) operation that has not yet returned to return immediately. |
int |
write(ByteBuffer src)
Writes a sequence of bytes from the given buffer.
|
close
SocketAddress getLocalAddress() throws IOException
IOException
- if an I/O error occurs when getting the local addressSocketAddress getRemoteAddress() throws IOException
IOException
- if an I/O error occurs when getting the remote address<T> void setOption(SocketOption<T> name, T value) throws IOException
StandardSocketOptions
).T
- the type of the socket option valuename
- the name of the socket optionvalue
- the value of the socket optionIOException
- if an I/O error occurs when setting the socket optionUnsupportedOperationException
- if the socket option is not supportedIllegalArgumentException
- if the value is invalid for the socket optionvoid setPerformancePreferences(int connectionTime, int latency, int bandwidth)
This method does not have a consistent behavior across different operating systems and platforms.
connectionTime
- an int
expressing the relative weighting given to a short connection timelatency
- an int
expressing the relative weighting given to low latencybandwidth
- an int
expressing the relative weighting given to high bandwidthint read(ByteBuffer dst) throws IOException
dst
- the buffer into which bytes are to be transferred.IOException
- If some other I/O error occurs.void waitRead(long timeout, TimeUnit timeUnit) throws IOException
wakeupRead()
method is invoked, the current thread is interrupted, or the given
timeout period expires, whichever comes first.timeout
- if positive, block for up to timeout in specified time unit, more or less, while waiting for a
socket to become read ready; if zero, block indefinitely; must not be negative.timeUnit
- time unit of the timeout.IOException
- If some other I/O error occurs.void wakeupRead()
waitRead(long, TimeUnit)
operation that has not yet returned to return immediately.int write(ByteBuffer src) throws IOException
src
- the buffer from which bytes are to be retrieved.IOException
- If some other I/O error occurs.void waitWrite(long timeout, TimeUnit timeUnit) throws IOException
wakeupWrite()
method is invoked, the current thread is interrupted, or the given
timeout period expires, whichever comes first.timeout
- if positive, block for up to timeout in specified time unit, more or less, while waiting for a
socket to become write ready; if zero, block indefinitely; must not be negative.timeUnit
- time unit of the timeout.IOException
- If some other I/O error occurs.void wakeupWrite()
waitWrite(long, TimeUnit)
operation that has not yet returned to return immediately.boolean isBlocking()
true
if, and only if, this socket is in blocking mode.void setBlocking(boolean blocking) throws IOException
blocking
- true
for block until I/O operation completes, false
otherwise.IOException
- If some other I/O error occurs.Copyright © 2005–2024 Onix Solutions. All rights reserved.