import java.io.*;

public class Dialog {
    DataInputStream inputStream;
    PrintStream     outputStream;

    Dialog(InputStream is, OutputStream os) {
	inputStream = new DataInputStream(is);
	outputStream = new PrintStream(os);
    }

    void run() {
	outputStream.println("220 Hello sir! I am waiting for commands!");
	// Receive and process orders line by line
	while (true) {
	    String line;
	    try {
		line = inputStream.readLine();
	    }
	    catch (IOException e) {
		System.err.println(e);
		return;
	    }

	    if (line == null) {
		return;
	    }
	    if (line.equals("quit")) {
		outputStream.println("221 Ok, closing connection"); 
		return;
	    } else if (line.equals("hello")) {
		outputStream.println("250 Hello sir, howdy ?");
	    } else {
		outputStream.println("500 Sorry sir, unknown command: " + line);
	    }
	}
    }
}
