Skip navigation links


Adds a layer between the application and the java.nio.channels package.

See: Description

Package Description

Adds a layer between the application and the java.nio.channels package. java.nio.channels.Selector is placed into a separate SelectorThread. AsyncDatagramSocket, AsyncMulticastSocket, AsyncSocket and AsyncServerSocket encapsulate a and registers that channel with the selector thread. The selector thread informs these asynchronous sockets when I/O operations are possible.

The selector thread is automatically started by the network package on behalf of the application. The selector thread is a daemon thread and terminates when the application exits.

Upon successfully completing the I/O operation, the asynchronous socket calls its listener, passing the operation results. I/O operations and listener calls are performed in the SelectorThread.

This package follows the API design, provide separate classes for multicast and non-multicast datagram sockets. Project developers' experience shows that these two socket types are distinct in use. There is no need to open one UDP socket and use it for both multicast and non-multicast purposes. Further, multicast UDP sockets require a different binding than non-multicast UDP sockets (if any), resulting in using one UDP socket for both purposes problematic.

The eBus network package provides three utility classes:

  1. InetServices: This is Dan Anderson's utility class with some modifications. This fills in functionality missing from translating a TCP or UDP service name into a port number.
  2. InetAddressComparator: provides comparison between two instances.
  3. InetSocketAddressComparator: provides comparison between two instances.

Building connections

As of eBus release 4.5.1 the preferred API for opening TCP and datagram connections is to use the builder classes. Builders provide a simpler and flexible API for configuring and creating connections. The following table connects the builder class with the target connection:

eBus Connection Builders
Connection Class Builder Class
AsyncServerSocket AsyncServerSocket.ServerBuilder
AsyncSocket AsyncSocket.SocketBuilder
AsyncDatagramSocket AsyncDatagramSocket.DatagramBuilder
AsyncMulticastSocket AsyncMulticastSocket.MulticastBuilder

Builder instances are accessed by called the async socket builder method. For example:

final AsyncSocket.SocketBuilder builder = AsyncSocket.builder();
Skip navigation links