protected void readDataFromSocket(SelectionKey key) throws Exception {
		SocketChannel socketChannel = (SocketChannel) key.channel();
		int count;
		
		buffer.clear();
		
		//Loop while data is available; channel is nonblocking
		while((count = socketChannel.read(buffer)) > 0) {
			buffer.flip(); //Make buffer readable
			
			//Send the data; don't assume it goes all at once
			while(buffer.hasRemaining()) {
				socketChannel.write(buffer);
			}
			
			// WARNING: the above loop is evil. Because
			// it's writing back to the same nonblocking
			// channel it read the data from, this code can
			// potentially spin in a busy loop. In real life
			// you'd do something more useful than this.
			
			buffer.clear(); //Empty the bufferx
		}
		
		if(count < 0) {
			//Close channel on EOF, invalidates the key
			socketChannel.close();
		}
	}