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

Fix: removed server lag.

parent 4305b9d0
No related branches found
No related tags found
2 merge requests!35Update: Added more Stuff to be transported over the server.,!2Merge of Multiplayer Feature into development branch
......@@ -7,16 +7,17 @@ public class ConnectionHandling {
public static void main(String[] args) throws IOException, InterruptedException {
Client client = new Client();
client.startConnection("192.168.0.105", 4444);
for (int i = 1; i < 3; i++){
client.startConnection("localhost", 4444);
for (int i = 1; i < 10; i++){
int x = client.sendX(1+i);
System.out.println(x);
int y = client.sendY(0+i);
TimeUnit.MILLISECONDS.sleep(100);
int y = client.sendY(i);
System.out.println(y);
TimeUnit.SECONDS.sleep(1);
}
}
}
package de.hdm_stuttgart.battlearena.Model.Multiplayer.TestServer;
import de.hdm_stuttgart.battlearena.Model.Multiplayer.GameServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.*;
import java.io.*;
import java.util.concurrent.Executors;
......@@ -7,17 +11,21 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Server {
private static final Logger log = LogManager.getLogger(Server.class);
private ServerSocket serverSocket;
private static int px;
private static int py;
public static void main(String[] args) throws IOException {
Server server = new Server();
server.start("192.168.0.105",4444);
log.info("server starting...");
server.start("localhost",4444);
}
public void start(String lolcalhost, int port) throws IOException {
serverSocket = new ServerSocket(port);
log.info("server started!");
while (true)
new ServerHandler(serverSocket.accept()).start();
}
......@@ -52,15 +60,21 @@ public class Server {
int receivedX = Integer.parseInt(inputLine.substring(2));
px = receivedX;
localOut.println(inputLine);
localOut.flush();
log.info("Current X and Y: " + px + " / " + py);
log.info("Sent response to client: " + receivedX);
} else if (inputLine.startsWith("y:")) {
int receivedY = Integer.parseInt(inputLine.substring(2));
py = receivedY;
localOut.println(inputLine);
localOut.flush();
log.info("Current X and Y: " + px + " / " + py);
log.info("Sent response to client: " + receivedY);
}
localOut.println(inputLine);
localOut.flush();
System.out.println("Current X: " + px + " Current Y: " + py);
System.out.println("Sent response to client: " + inputLine);
}
} catch (IOException e) {
throw new RuntimeException(e);
......
......@@ -4,6 +4,7 @@ module gui {
requires javafx.media;
requires org.apache.logging.log4j;
opens de.hdm_stuttgart.battlearena to javafx.fxml;
exports de.hdm_stuttgart.battlearena.Main;
exports de.hdm_stuttgart.battlearena.Controller;
......
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