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 {
private static int enemyY = 0;
private static int playerID = 0;
private static int[] coordinates = {pX,pY,playerID};
private static String ipaddress = "localhost";
private static final Logger log = LogManager.getLogger(ConnectionHandler.class);
public void startHandler() throws IOException, InterruptedException {
Client client = new Client();
client.startConnection("localhost", 4444);
client.startConnection(ipaddress, 4444);
ConnectionThread connectionthread = new ConnectionThread(client);
connectionthread.start();
......@@ -85,12 +85,8 @@ public class ConnectionHandler {
return enemyY;
}
public void setEnemyX(int enemyX) {
ConnectionHandler.enemyX = enemyX;
}
public void setEnemyY(int enemyY) {
ConnectionHandler.enemyY = enemyY;
public static void setIpaddress(String ipaddress) {
ConnectionHandler.ipaddress = ipaddress;
}
}
......@@ -23,10 +23,18 @@ public class Server {
private static int playerID;
private static int playercount = 0;
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 {
/* 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();
log.info("server starting...");
server.start("localhost",4444);
......@@ -35,6 +43,7 @@ public class Server {
public void start(String host_ip, int port) throws IOException {
serverSocket = new ServerSocket(port);
log.info("server started!");
started = true;
while (true){
new ServerHandler(serverSocket.accept()).start();
}
......@@ -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 {
}
}
public static void main(String[] args) {
launch(args);
public static void main(String[] args) throws IOException {
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