Interface Channel

All Superinterfaces:
AttributeMap, ChannelOutboundInvoker, Comparable<Channel>
All Known Subinterfaces:
DatagramChannel, DomainDatagramChannel, DomainSocketChannel, DuplexChannel, Http2StreamChannel, QuicChannel, QuicStreamChannel, SctpChannel, SctpServerChannel, ServerChannel, ServerDomainSocketChannel, ServerSocketChannel, SocketChannel, UdtChannel, UdtServerChannel, UnixChannel
All Known Implementing Classes:
AbstractChannel, AbstractEpollServerChannel, AbstractEpollStreamChannel, AbstractKQueueServerChannel, AbstractKQueueStreamChannel, AbstractNioByteChannel, AbstractNioChannel, AbstractNioMessageChannel, AbstractOioByteChannel, AbstractOioChannel, AbstractOioMessageChannel, AbstractServerChannel, EmbeddedChannel, EpollDatagramChannel, EpollDomainDatagramChannel, EpollDomainSocketChannel, EpollServerDomainSocketChannel, EpollServerSocketChannel, EpollSocketChannel, IoUringDatagramChannel, IoUringDomainSocketChannel, IoUringServerDomainSocketChannel, IoUringServerSocketChannel, IoUringSocketChannel, KQueueDatagramChannel, KQueueDomainDatagramChannel, KQueueDomainSocketChannel, KQueueServerDomainSocketChannel, KQueueServerSocketChannel, KQueueSocketChannel, LocalChannel, LocalServerChannel, NioDatagramChannel, NioDomainSocketChannel, NioSctpChannel, NioSctpServerChannel, NioServerDomainSocketChannel, NioServerSocketChannel, NioSocketChannel, NioUdtAcceptorChannel, NioUdtByteAcceptorChannel, NioUdtByteConnectorChannel, NioUdtByteRendezvousChannel, NioUdtMessageAcceptorChannel, NioUdtMessageConnectorChannel, NioUdtMessageRendezvousChannel, OioByteStreamChannel, OioDatagramChannel, OioSctpChannel, OioSctpServerChannel, OioServerSocketChannel, OioSocketChannel, RxtxChannel

public interface Channel extends AttributeMap, ChannelOutboundInvoker, Comparable<Channel>
A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.

A channel provides a user:

  • the current state of the channel (e.g. is it open? is it connected?),
  • the configuration parameters of the channel (e.g. receive buffer size),
  • the I/O operations that the channel supports (e.g. read, write, connect, and bind), and
  • the ChannelPipeline which handles all I/O events and requests associated with the channel.

All I/O operations are asynchronous.

All I/O operations in Netty are asynchronous. It means any I/O calls will return immediately with no guarantee that the requested I/O operation has been completed at the end of the call. Instead, you will be returned with a ChannelFuture instance which will notify you when the requested I/O operation has succeeded, failed, or canceled.

Channels are hierarchical

A Channel can have a parent depending on how it was created. For instance, a SocketChannel, that was accepted by ServerSocketChannel, will return the ServerSocketChannel as its parent on parent().

The semantics of the hierarchical structure depends on the transport implementation where the Channel belongs to. For example, you could write a new Channel implementation that creates the sub-channels that share one socket connection, as BEEP and SSH do.

Downcast to access transport-specific operations

Some transports exposes additional operations that is specific to the transport. Down-cast the Channel to sub-type to invoke such operations. For example, with the old I/O datagram transport, multicast join / leave operations are provided by DatagramChannel.

Release resources

It is important to call close() or close(ChannelPromise) to release all resources once you are done with the Channel. This ensures all resources are released in a proper way, i.e. filehandles.