Code example for SocketChannel

Methods: configureBlocking, register

0
		selector = Selector.open();
 
		readBuffer = ByteBuffer.allocate(READ_BUFFER_SIZE);
		writeBuffer = ByteBuffer.allocate(WRITE_BUFFER_SIZE);
 
		channel.configureBlocking(false);
		channel.register(selector, SelectionKey.OP_READ);
	} 
 
	/** 
	 * Attempts to read from the client socket, filling the read buffer 
	 * 
	 * @return false if the socket was closed or an I/O error occured 
	 */ 
	public boolean readFromSocket() 
	{ 
		try { 
			int channelsReady = selector.select();
 
			if (channelsReady == 0) { //Thread interrupted or select() failed
				return false;