This class works with {@link NetworkSend} and {@link NetworkReceive} to transmit size-delimited network requests andresponses.
A connection can be added to the selector associated with an integer id by doing
selector.connect(42, new InetSocketAddress("google.com", server.port), 64000, 64000);The connect call does not block on the creation of the TCP connection, so the connect method only begins initiating the connection. The successful invocation of this method does not mean a valid connection has been established. Sending requests, receiving responses, processing connection completions, and disconnections on the existing connections are all done using the
poll()
call. List<NetworkRequest> requestsToSend = Arrays.asList(new NetworkRequest(0, myBytes), new NetworkRequest(1, myOtherBytes)); selector.poll(TIMEOUT_MS, requestsToSend);The selector maintains several lists that are reset by each call to
poll()
which are available via various getters. These are reset by each call to poll()
. This class is not thread safe!
|
|