| Modifier and Type | Field and Description |
|---|---|
protected io.netty.bootstrap.Bootstrap |
bootstrap |
protected long |
bytesRead |
protected long |
bytesWrote |
protected io.netty.channel.Channel |
channel |
protected IOService |
service |
| Modifier and Type | Method and Description |
|---|---|
void |
addOnDataReceivedListener(Callback<Socket> cbk)
Adds a
Callback that will be called every time some data
is available to read. |
void |
bind()
Binds the socket to any port in the default interface without
connecting to some remote endpoint.
|
void |
bind(java.net.SocketAddress local)
Binds the socket to a local address.
|
protected void |
checkSocketCreated(java.lang.String method)
Call this method to check if the socket is created, if it's not,
then throws a
SocketNotCreated exception. |
void |
close()
Closes the socket after the current operation is done.
|
Future<java.lang.Void> |
closeAsync()
Closes the socket after the current operation is done, and then
calls
cbk with the result, either successful or failure. |
void |
connect(java.net.InetAddress address,
int port)
Binds the socket to a random port and connects to the remote endpoint as
address and port. |
void |
connect(java.net.SocketAddress endpoint)
Binds the socket to a random port and connects to the remote
endpoint.
|
void |
connect(java.lang.String hostName,
int port,
DNSServerProvider provider)
Binds the socket to a random port and connects to the remote endpoint as
hostName and port. |
Future<java.lang.Void> |
connectAsync(java.net.InetAddress address,
int port)
Binds the socket to a random port and connects to the remote endpoint as
address and port. |
Future<java.lang.Void> |
connectAsync(java.net.SocketAddress endpoint)
Binds the socket to a random port and connects to the remote endpoint
asynchronously.
|
Future<java.lang.Void> |
connectAsync(java.lang.String hostName,
int port,
DNSServerProvider provider)
Binds the socket to a random port and connects to the remote endpoint as
hostName and port. |
protected <ReturnType> |
createFuture(io.netty.util.concurrent.Future<ReturnType> n) |
protected <ReturnType> |
createFuture(Procedure whenCancelled) |
protected void |
fireReceivedData()
Calls all methods that want to be notified when some data have
been received.
|
boolean |
isOpen() |
java.net.SocketAddress |
localEndpoint()
Gets the
SocketAddress of the local socket, or returns
null if the socket is not created yet using one of the
connect or bind methods. |
long |
receive(io.netty.buffer.ByteBuf data)
Receives some data from the socket into the
ByteBuf. |
abstract long |
receive(io.netty.buffer.ByteBuf data,
int bytes)
Receives some data from the socket and writes it into the
ByteBuf
data a maximum of bytes bytes. |
Future<java.lang.Long> |
receiveAsync(io.netty.buffer.ByteBuf data)
Receives some data from the socket into the
ByteBuf. |
abstract Future<java.lang.Long> |
receiveAsync(io.netty.buffer.ByteBuf data,
int bytes)
Receives some data from the socket and writes it into the
ByteBuf
data a maximum of bytes bytes. |
long |
receivedBytes() |
java.net.SocketAddress |
remoteEndpoint()
Gets the
SocketAddress of the remote endpoint if this socket
is connected to one. |
long |
send(io.netty.buffer.ByteBuf data)
Sends some data stored in the
ByteBuf data, starting from its
current position with a size of data.remaining() bytes. |
long |
send(io.netty.buffer.ByteBuf data,
int bytes)
Sends some data stored in the
ByteBuf data, starting from its
current position with a size of bytes. |
long |
send(java.lang.String data)
Sends the contents of the
String using the default platform Charset,
without any extra characters. |
Future<java.lang.Void> |
sendAsync(io.netty.buffer.ByteBuf data)
Sends some data stored in the
ByteBuf data, with the remaining
bytes of it. |
Future<java.lang.Void> |
sendAsync(io.netty.buffer.ByteBuf data,
int bytes)
Sends some data stored in the
ByteBuf data, starting from its
current position with a size of bytes. |
Future<java.lang.Void> |
sendAsync(java.lang.String data)
Sends the contents of the
String using the default platform Charset,
without any extra characters. |
long |
sendBytes() |
<T> boolean |
setOption(io.netty.channel.ChannelOption<T> type,
T value)
Changes an option of this socket with a new value.
|
protected final IOService service
protected io.netty.channel.Channel channel
protected io.netty.bootstrap.Bootstrap bootstrap
protected long bytesRead
protected long bytesWrote
public void close()
Throwable if an error occurs. This operation
blocks the thread.close in interface java.lang.AutoCloseable@NotNull public Future<java.lang.Void> closeAsync()
cbk with the result, either successful or failure.public void bind(@NotNull
java.net.SocketAddress local)
local - address to bindpublic void bind()
public void connect(@NotNull
java.net.SocketAddress endpoint)
throws java.lang.InterruptedException
endpoint - remote endpointjava.lang.InterruptedException - When this Thread is interrupted@NotNull public Future<java.lang.Void> connectAsync(@NotNull java.net.SocketAddress endpoint)
Future where the task can be managed.endpoint - remote endpoint to connectFuture of the taskpublic void connect(@NotNull
java.net.InetAddress address,
int port)
throws java.lang.InterruptedException
address and port.address - address of the remote endpointport - port of the remote endpointjava.lang.InterruptedException - When this Thread is interrupted while waiting to connectpublic void connect(@NotNull
java.lang.String hostName,
int port,
@NotNull
DNSServerProvider provider)
throws java.net.UnknownHostException,
java.lang.InterruptedException
hostName and port.hostName - domain of the remote endpointport - port of the remote endpointprovider - A DNSServerProvider implementationjava.lang.InterruptedException - When this Thread is interrupted while waiting to connectjava.net.UnknownHostException - If the hostName cannot be resolved@NotNull public Future<java.lang.Void> connectAsync(@NotNull java.net.InetAddress address, int port)
address and port.address - address of the remote endpointport - port of the remote endpointFuture of the task@NotNull public Future<java.lang.Void> connectAsync(@NotNull java.lang.String hostName, int port, @NotNull DNSServerProvider provider) throws java.net.UnknownHostException
hostName and port.hostName - domain of the remote endpointport - port of the remote endpointprovider - A DNSServerProvider implementationFuture of the taskjava.net.UnknownHostException - If the hostName cannot be resolvedpublic abstract long receive(io.netty.buffer.ByteBuf data,
int bytes)
throws java.lang.Throwable
ByteBuf
data a maximum of bytes bytes. This method don't read exactly
bytes bytes, only at most. To ensure read all the bytes, use one of the
SocketUtil methods.data - buffer where to write on all the databytes - maximum number of bytes to readjava.lang.Throwable - if the receive operation fails, throws something@NotNull public abstract Future<java.lang.Long> receiveAsync(io.netty.buffer.ByteBuf data, int bytes)
ByteBuf
data a maximum of bytes bytes. This method don't read exactly
bytes bytes, only at most. To ensure read all the bytes, use one of the
SocketUtil methods. This operation is done asynchronously, so returns a
Future for the task.data - buffer where to write on all the databytes - maximum number of bytes to readFuture representing this taskpublic long send(@NotNull
io.netty.buffer.ByteBuf data,
int bytes)
throws java.lang.InterruptedException
ByteBuf data, starting from its
current position with a size of bytes. Depending on the implementation
and its options, is possible that the data could not be sent in the moment, or
only a portion of it is sent.data - buffer with the data to be sentbytes - number of bytes to sendjava.lang.InterruptedException - If there's an interruption while sending the data@NotNull public Future<java.lang.Void> sendAsync(io.netty.buffer.ByteBuf data, int bytes)
ByteBuf data, starting from its
current position with a size of bytes. Depending on the implementation
and its options, is possible that the data could not be sent in the moment, or
only a portion of it is sent. This is an asynchronous operation, so returns a
Future representing the task.data - buffer with the data to be sentbytes - number of bytes to sendFuture representing this task@NotNull public Future<java.lang.Void> sendAsync(@NotNull io.netty.buffer.ByteBuf data)
ByteBuf data, with the remaining
bytes of it. Depending on the implementation and its options, is possible that
the data could not be sent in the moment, or only a portion of it is sent. This
is an asynchronous operation, so returns a Future representing the task.data - buffer with the data to be sentFuture representing this taskpublic long receive(@NotNull
io.netty.buffer.ByteBuf data)
throws java.lang.Throwable
ByteBuf. This method
doesn't ensure to write exactly data.remaining() bytes. Use instead
SocketUtil methods.data - ByteBuf where to write the datajava.lang.Throwable - If something bad happens while receiving the data@NotNull public Future<java.lang.Long> receiveAsync(@NotNull io.netty.buffer.ByteBuf data)
ByteBuf. This method
doesn't ensure to write exactly data.remaining() bytes. Use instead
SocketUtil methods. This is an asynchronous operation, so it returns
a Future about this task.data - ByteBuf where to write the dataFuture representing the taskpublic long send(@NotNull
io.netty.buffer.ByteBuf data)
throws java.lang.InterruptedException
ByteBuf data, starting from its
current position with a size of data.remaining() bytes. Depending on the implementation
and its options, is possible that the data could not be sent in the moment, or
only a portion of it is sent.data - ByteBuf with the data to be sendjava.lang.InterruptedException - if the send operation is interrupted@NotNull public Future<java.lang.Void> sendAsync(@NotNull java.lang.String data)
String using the default platform Charset,
without any extra characters. Depending on the implementation and its options,
is possible that the data could not be sent in the moment, or only a portion of
it is sent. That is an asynchronous operation, so it returns a Future
about this task.data - the String to sendFuture representing the taskpublic long send(@NotNull
java.lang.String data)
throws java.lang.InterruptedException
String using the default platform Charset,
without any extra characters. Depending on the implementation and its options,
is possible that the data could not be sent in the moment, or only a portion of
it is sent.data - the String to sendjava.lang.InterruptedException - if the send operation is interruptedpublic <T> boolean setOption(@NotNull
io.netty.channel.ChannelOption<T> type,
@NotNull
T value)
T - Type of the new value for the optiontype - Option to changevalue - New valueChannelOptionpublic java.net.SocketAddress remoteEndpoint()
SocketAddress of the remote endpoint if this socket
is connected to one.null if not connectedpublic java.net.SocketAddress localEndpoint()
SocketAddress of the local socket, or returns
null if the socket is not created yet using one of the
connect or bind methods.public boolean isOpen()
public long sendBytes()
public long receivedBytes()
public void addOnDataReceivedListener(Callback<Socket> cbk)
Callback that will be called every time some data
is available to read. A receive operation called inside one of this
callbacks, will be added at the end of the read operation queue. If
there wasn't any receive operations before this one, a receive call
will not block and will return all possible data.cbk - listener for when some data is receivedprotected void fireReceivedData()
throws java.lang.Exception
java.lang.Exception - some errorprotected void checkSocketCreated(java.lang.String method)
SocketNotCreated exception.method - method that was calledprotected <ReturnType> FutureImpl<ReturnType> createFuture(Procedure whenCancelled)
protected <ReturnType> Future<ReturnType> createFuture(io.netty.util.concurrent.Future<ReturnType> n)