// Line server -- generic line-oriented server
// Al Williams
import java.io.*;
import java.net.*;

public class LineServer extends MTServerBase
{
    protected BufferedReader iread;
    protected BufferedWriter owrite;
    public boolean running=false;
    public void run() {
	try {
	    iread=new BufferedReader(new 
		InputStreamReader(socket.getInputStream()));
	    owrite=new BufferedWriter(new
		OutputStreamWriter(socket.getOutputStream()));
	    if (!init()) {
		socket.close();
		return;
	    }
	    running=true;
	    while (true) {
		String line = iread.readLine();
		if (!process(line)) {
		    running=false;
		    socket.close();
		    return;
		}
	    }
	}
	catch (IOException ioe) {
	    running=false;
	}

    }
    // You'll override this (and provide a main that calls startServer)
    public boolean process(String line) throws IOException {
	// this line is here just so we can throw IOExceptions
	// from subclasses
	if (line==null) throw new IOException();
	return false; // return true to end connection
    }

    // You'll override this if you want any custom start processing
    public boolean init() throws IOException {
	if (running) throw new IOException(); // just for subclass
	return true; // false to abort
    }
}

