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

Update: Server class and serverhandler class can now be started by creating a...

Update: Server class and serverhandler class can now be started by creating a class instance, ipaddress can also be set each with a setter.
parent 0b301304
No related branches found
No related tags found
1 merge request!35Update: Added more Stuff to be transported over the server.
...@@ -15,13 +15,13 @@ public class ConnectionHandler { ...@@ -15,13 +15,13 @@ public class ConnectionHandler {
private static int enemyY = 0; private static int enemyY = 0;
private static int playerID = 0; private static int playerID = 0;
private static int[] coordinates = {pX,pY,playerID}; private static int[] coordinates = {pX,pY,playerID};
private static String ipaddress = "localhost";
private static final Logger log = LogManager.getLogger(ConnectionHandler.class); private static final Logger log = LogManager.getLogger(ConnectionHandler.class);
public void startHandler() throws IOException, InterruptedException { public void startHandler() throws IOException, InterruptedException {
Client client = new Client(); Client client = new Client();
client.startConnection("localhost", 4444); client.startConnection(ipaddress, 4444);
ConnectionThread connectionthread = new ConnectionThread(client); ConnectionThread connectionthread = new ConnectionThread(client);
connectionthread.start(); connectionthread.start();
...@@ -85,12 +85,8 @@ public class ConnectionHandler { ...@@ -85,12 +85,8 @@ public class ConnectionHandler {
return enemyY; return enemyY;
} }
public void setEnemyX(int enemyX) { public static void setIpaddress(String ipaddress) {
ConnectionHandler.enemyX = enemyX; ConnectionHandler.ipaddress = ipaddress;
}
public void setEnemyY(int enemyY) {
ConnectionHandler.enemyY = enemyY;
} }
} }
...@@ -23,10 +23,18 @@ public class Server { ...@@ -23,10 +23,18 @@ public class Server {
private static int playerID; private static int playerID;
private static int playercount = 0; private static int playercount = 0;
private static int[] cords; private static int[] cords;
private static int[] returncords = {enemyx,enemyy,playerID}; private static int[] returncords = {enemyx,enemyy,playerID};
private boolean started = false;
private static String ipaddress = "localhost";
public static void main(String[] args) throws IOException { /* 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);
} */
public void startServer() throws IOException {
Server server = new Server(); Server server = new Server();
log.info("server starting..."); log.info("server starting...");
server.start("localhost",4444); server.start("localhost",4444);
...@@ -35,6 +43,7 @@ public class Server { ...@@ -35,6 +43,7 @@ public class Server {
public void start(String host_ip, int port) throws IOException { public void start(String host_ip, int port) throws IOException {
serverSocket = new ServerSocket(port); serverSocket = new ServerSocket(port);
log.info("server started!"); log.info("server started!");
started = true;
while (true){ while (true){
new ServerHandler(serverSocket.accept()).start(); new ServerHandler(serverSocket.accept()).start();
} }
...@@ -145,4 +154,10 @@ public class Server { ...@@ -145,4 +154,10 @@ public class Server {
} }
} }
public boolean isStarted() {
return started;
}
public static void setIpaddress(String ipaddress) {
Server.ipaddress = ipaddress;
}
} }
...@@ -107,8 +107,7 @@ public class TestMap extends Application { ...@@ -107,8 +107,7 @@ public class TestMap extends Application {
} }
} }
public static void main(String[] args) { public static void main(String[] args) throws IOException {
launch(args); launch(args);
} }
} }
\ No newline at end of file
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