Future<Integer> readval = client.read(buffer);
String serverResponse = new String(buffer.array()).trim();
System.out.println("Received from server: " + serverResponse);
readval.get();
You cannot read the serverResponse immediately after requesting the read. It's called Async for a reason, and returns a 'Future' for the very same reason.
readval.get() will block until the read is completed, after which you may read the response. Not before.
To properly utilize the async-aspect of it, you should get the response at some point after readval.isDone() is true, or better yet retrieve the response from a completionhandler by using the overload AsynchronousSocketChannel#read(ByteBuffer, Attachment, CompletionHandler). The completionhandler will execute once the result is ready.