Giving full control of the buffer to the server

Setting the buffer size according to the given length, so the server can deal with it
also avoiding the while loop to continue, giving full control of the buffer to the server