(ServerSocketChannel) key.channel(); SocketChannel channel = server.accept(); registerChannel (selector,

(ServerSocketChannel) key.channel(); SocketChannel channel = server.accept(); registerChannel (selector, channel, SelectionKey.OP_READ); sayHello (channel); } // Is there data to read on this channel? if (key.isReadable()) { readDataFromSocket (key); } // Remove key from selected set; it’s been handled it.remove(); } } } // ———————————————————- /** * Register the given channel with the given selector for * the given operations of interest */ protected void registerChannel (Selector selector, SelectableChannel channel, int ops) throws Exception { if (channel == null) { return; // could happen } // Set the new channel nonblocking channel.configureBlocking (false); // Register it with the selector channel.register (selector, ops); } // ———————————————————- // Use the same byte buffer for all channels. A single thread is // servicing all the channels, so no danger of concurrent acccess. private ByteBuffer buffer = ByteBuffer.allocateDirect (1024); /** * Sample data handler method for a channel with data ready to read. * @param key A SelectionKey object associated with a channel * determined by the selector to be ready for reading. If the * channel returns an EOF condition, it is closed here, which * automatically invalidates the associated key. The selector * will then de-register the channel on the next select call. */ protected void readDataFromSocket (SelectionKey key) throws Exception 149
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services

Comments are closed.