diff --git a/bin/org/eu/lumiere/net/WebServer.class b/bin/org/eu/lumiere/net/WebServer.class deleted file mode 100644 index c21063f..0000000 Binary files a/bin/org/eu/lumiere/net/WebServer.class and /dev/null differ diff --git a/src/org/eu/lumiere/net/WebServer.java b/src/org/eu/lumiere/net/WebServer.java deleted file mode 100644 index f33d447..0000000 --- a/src/org/eu/lumiere/net/WebServer.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.eu.lumiere.net; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; - -import org.eu.lumiere.loggers.GlobalLogger; -import org.eu.lumiere.loggers.GlobalLogger.LogLevel; - -public class WebServer implements Runnable { - - private GlobalLogger l = GlobalLogger.getLogger(); - private String threadName = "Lumiere server thread"; - private boolean isRunning = false; - private Thread thread; - - private int port = 8080; - private ServerSocket server; - private ServerEvents e; - - public WebServer(String name, ServerEvents e, int port) { - this.threadName = name == null ? this.threadName : name; - this.port = port; - this.e = e; - } - - public synchronized void start() { - if(isRunning || thread != null) { - l.printf(LogLevel.WARNING, threadName + " is already running", null); - return; - } - - try { - server = new ServerSocket(port); - } catch (Exception ex) { - l.printf(LogLevel.ERROR, ex instanceof IllegalArgumentException ? - "Server port must be between 0 and 65535" : ex.getMessage(), null); - } - - thread = new Thread(this, threadName); - isRunning = true; - thread.start(); - } - - public synchronized void stop() { - if(!isRunning || thread == null) { - l.printf(LogLevel.WARNING, threadName + " is already running", null); - return; - } - - thread.interrupt(); - isRunning = false; - thread = null; - - if(server != null) { - try { - server.close(); - } catch (IOException e) { - l.printf(LogLevel.ERROR, e.getMessage(), null); - } - } - } - - @Override - public void run() { - l.printf(LogLevel.INFO, threadName + " using port " + getPort(), null); - while(isRunning && !thread.isInterrupted()) { - try { - - if(server == null) { - stop(); - continue; - } - - Socket s = server.accept(); - if(e != null) - e.onConnection(s); - l.printf(LogLevel.INFO, "New Connection " + s.getInetAddress().getHostAddress(), null); - } catch (IOException ex) { - l.printf(LogLevel.ERROR, ex.getMessage(), null); - } - } - l.printf(LogLevel.INFO, threadName + " has been stopped", null); - } - - public int getPort() { - return this.port; - } - -}