public class TCPAcceptor extends Acceptor<TCPSocket>
Accepts TCP connections, and creates TCPSocket for any new one.
When bound, any new connection is notified to the first acceptAsync()
or Acceptor.accept() calls, passed to the listener or stored in a queue; all
in this order. When the new connection is stored in the queue, a new call of
acceptAsync() or Acceptor.accept() will return without blocking the
first TCPSocket in the queue.
The method pendingConnections() will tell you how many sockets are
waiting to be accepted, or how many accept() calls are waiting for
new connections, if the value is negative.
bootstrap, channel, onConnection, service| Constructor and Description |
|---|
TCPAcceptor(IOService service)
Creates a TCP acceptor for server applications.
|
TCPAcceptor(IOService server,
IOService worker)
Creates a TCP acceptor for server applications.
|
| Modifier and Type | Method and Description |
|---|---|
Future<TCPSocket> |
acceptAsync()
Accepts a connection from any client and returns the
Socket. |
protected TCPSocket |
createSocketForImplementation(io.netty.channel.socket.SocketChannel ch) |
int |
pendingConnections() |
void |
setOnConnectionListener(Callback<TCPSocket> cbk)
Instead of using
Acceptor.accept() or Acceptor.acceptAsync(), it is
possible to use a listener to receive any new connection to the
acceptor. |
accept, bind, bind, bind, checkSocketCreated, close, closeAsync, createFuture, createFuture, onClose, setChildOption, setOption, waitForClosepublic TCPAcceptor(IOService service)
service - IOService for the acceptor and the sockets@NotNull protected TCPSocket createSocketForImplementation(@NotNull io.netty.channel.socket.SocketChannel ch) throws java.io.IOException
java.io.IOExceptionpublic Future<TCPSocket> acceptAsync()
AcceptorSocket.acceptAsync in class Acceptor<TCPSocket>Future with the accept taskpublic void setOnConnectionListener(Callback<TCPSocket> cbk)
AcceptorAcceptor.accept() or Acceptor.acceptAsync(), it is
possible to use a listener to receive any new connection to the
acceptor. It is complementary of the before methods, so if one of the
before methods are called, the new connection will be returned in this
calls, not in the listener.setOnConnectionListener in class Acceptor<TCPSocket>cbk - a listener that will be called when a new connection occurspublic int pendingConnections()
accept() calls that are waiting a new connection.