| @@ -26,6 +26,10 @@ import javafx.scene.text.Font; | |||||
| import javafx.scene.text.Text; | import javafx.scene.text.Text; | ||||
| import javafx.stage.Stage; | import javafx.stage.Stage; | ||||
| import javafx.stage.StageStyle; | import javafx.stage.StageStyle; | ||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | |||||
| import java.net.ServerSocket; | |||||
| public class Main extends Application { | public class Main extends Application { | ||||
| @@ -98,9 +102,35 @@ public class Main extends Application { | |||||
| * @param args Commandline parameters | * @param args Commandline parameters | ||||
| */ | */ | ||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| if (isRunning()) { | |||||
| LoggerFactory.getLogger(Main.class).error("App already running or Port 1111 in use."); | |||||
| System.exit(2); | |||||
| } | |||||
| launch(args); | launch(args); | ||||
| } | } | ||||
| /** | |||||
| * @return true wenn der Port 1111 bereits belegt ist, false sonst. | |||||
| */ | |||||
| private static boolean isRunning() { | |||||
| ServerSocket socket = null; | |||||
| try { | |||||
| socket = new ServerSocket(1111); | |||||
| socket.setReuseAddress(true); | |||||
| return false; | |||||
| } catch (IOException ignored) { | |||||
| } finally { | |||||
| if (socket != null) { | |||||
| try { | |||||
| socket.close(); | |||||
| } catch (IOException ignored) { | |||||
| } | |||||
| } | |||||
| } | |||||
| return true; | |||||
| } | |||||
| @Override | @Override | ||||
| public void stop() throws Exception { | public void stop() throws Exception { | ||||
| if (server != null) { | if (server != null) { | ||||