/**
*
*/
package info.walnutstreet.vs.ps01.server;
import info.walnutstreet.vs.ps01.common.Log;
import info.walnutstreet.vs.ps01.server.listener.Listener;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.Scanner;
/**
* @author Christoph Gostner, Romedius Weiss, Christian Bitschnau
* @author Christian Bitschnau
* @version 0.2
*/
public class Server {
/**
* Listener class of the server.
*/
private Listener listener;
/**
* Constructor.
*
* @throws IOException
*/
public Server() throws IOException {
this.listener = new Listener();
}
/**
* Start the listen process.
* The method generates a thread with the listener
* class and starts it.
*/
private void startListener() {
new Thread(this.listener).start();
}
/**
* This method starts the listen process of the process.
* The generated Listener Thread listens for incoming
* connections and tries to handle them.
* The server can be closed by typing quit into the console,
* where the server was started.
*/
public void startServer() {
this.startListener();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("$ ");
String line = scanner.nextLine();
if ("quit".equals(line)) {
break;
}
}
this.listener.stopListen();
}
/**
* Main method - start the server.
*
* @param args Ignored
*/
public static void main(String[] args) {
try {
Server server = new Server();
server.startServer();
} catch (SocketTimeoutException e) {
Log.error(e.toString());
} catch (IOException e) {
Log.error(e.toString());
}
}
}