Skip to content
Snippets Groups Projects
Commit ea00021f authored by Busch Elias's avatar Busch Elias
Browse files

Update: changed the while loop in server to a Thread to be able to stop the server.

parent 758a4250
No related branches found
No related tags found
4 merge requests!54Update: coreMaps.json (added new maps),!39Merge Request,!37eb093: Added: All other important values like Health, player direction etc are...,!35Update: Added more Stuff to be transported over the server.
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment