Package info.walnutstreet.vs.ps01.server

Source Code of info.walnutstreet.vs.ps01.server.Server

/**
*
*/
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());
    }
  }
}
TOP

Related Classes of info.walnutstreet.vs.ps01.server.Server

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.