I'm writing a simple DNS Server / Client and I'm having trouble getting the input buffer to take my whole input before doing the look up.
Java Code:
InetAddress hostAddress;
			
			int numBytes = fromClient.read(buffer);
			String host = new String(buffer, 0, numBytes);
			try {
				hostAddress = InetAddress.getByName(host);
				
				toClient.write(hostAddress.getHostAddress().getBytes());
				toClient.write("\r\n".getBytes()); //new line
				toClient.flush();
			}
			catch (UnknownHostException uhe) {
				toClient.write("Unknown Host".getBytes());
				toClient.flush();
			}
The fromClient is the InputStream and toClient is the OutputStream. numBytes is the length of the buffer. I have a server set up and I telnet into my localhost on a specific port and my server calls my connection class which calls this handler class where this code resides. everything is working except this bit o code.

If anyone has any ideas as to how to protect that buffer so it doesn't process immediately after 1 keystroke, I'd be grateful for the advice.

thanks,

Here's my whole class
Java Code:
import java.io.*;
import java.net.*;

public class Handler 
{
	public static final int BUFFER_SIZE = 2048;
	
	/**
	 * this method is invoked by a separate thread
	 */
	public void process(Socket client) throws java.io.IOException {
		byte[] buffer = new byte[BUFFER_SIZE];
		InputStream  fromClient = null;
		OutputStream toClient = null;
		
		try {
			/**
			 * get the input and output streams associated with the socket.
			 */
			fromClient = new BufferedInputStream(client.getInputStream());
			toClient = new BufferedOutputStream(client.getOutputStream());
			int numBytes;
			
			toClient.write("Connected to localhost.".getBytes());
			toClient.write("\r\n".getBytes()); //new line
			toClient.write("Escape character is '^]'.".getBytes());
			toClient.write("\r\n".getBytes()); //new line
			toClient.flush();
			
			InetAddress hostAddress;
			
			numBytes = fromClient.read(buffer);
			String host = new String(buffer, 0, numBytes);
			try {
				hostAddress = InetAddress.getByName(host);
				
				toClient.write(hostAddress.getHostAddress().getBytes());
				toClient.write("\r\n".getBytes()); //new line
				toClient.flush();
			}
			catch (UnknownHostException uhe) {
				toClient.write("Unknown Host".getBytes());
				toClient.flush();
			}
			
//			while ( (numBytes = fromClient.read(buffer)) != -1) {
//				String host = new String(buffer, 0, numBytes);
//				try {
//					hostAddress = InetAddress.getByName(host);
//					
//					toClient.write(hostAddress.getHostAddress().getBytes());
//					toClient.write("\r\n".getBytes()); //new line
//					toClient.flush();
//				}
//				catch (UnknownHostException uhe) {
//					toClient.write("Unknown Host".getBytes());
//					toClient.flush();
//				}
//									
//			}			
			client.close();
			
   		}
		catch (IOException ioe) {
			System.err.println(ioe);
		}
		finally {
			// close streams and socket
			if (fromClient != null)
				fromClient.close();
			if (toClient != null)
				toClient.close();
			if (client != null)
				client.close();
		}
	}
}