diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java index f3555e7b1f71b82a04f7bb75ebcd749f8bbe611a..37a84774188e9c0efbf59ce7298fe9295119c2cf 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Multiplayer/Server.java @@ -25,28 +25,38 @@ public class Server { private static int[] cords; private static int[] returncords = {enemyx,enemyy,playerID}; private boolean started = false; - private static String ipaddress = "localhost"; - /* public static void main(String[] args) throws IOException { //main method for testing purposes + public static void main(String[] args) throws IOException { //main method for testing purposes Server server = new Server(); log.info("server starting..."); - server.start(ipaddress, 4444); - } */ + server.start( 4444); + } public void startServer() throws IOException { Server server = new Server(); log.info("server starting..."); - server.start("localhost",4444); + server.start(4444); } - public void start(String host_ip, int port) throws IOException { + public void start(int port) throws IOException { serverSocket = new ServerSocket(port); log.info("server started!"); started = true; - while (true){ - new ServerHandler(serverSocket.accept()).start(); - } + + log.info("server accepting Thread starting..."); + Thread serverThread = new Thread(() -> { + while (true) { + try { + new ServerHandler(serverSocket.accept()).start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + serverThread.start(); + log.info("requests accepting Thread started!"); + } private static class ServerHandler extends Thread { @@ -115,7 +125,6 @@ public class Server { //set playerID: returncords[2] = 2; - } } @@ -157,7 +166,6 @@ public class Server { public boolean isStarted() { return started; } - public static void setIpaddress(String ipaddress) { - Server.ipaddress = ipaddress; - } + + }