it turns out i have the stupid (the WebServiceClient wasnt using threads.)
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m8s

This commit is contained in:
Daniella / Tove 2024-06-13 16:22:18 +02:00
parent 7ddf5f9349
commit 545296f2ce
Signed by: TudbuT
GPG key ID: B3CF345217F202D3

View file

@ -20,50 +20,52 @@ public class WebServiceClient {
public static void connect() { public static void connect() {
if(inputStream != null || outputStream != null) if(inputStream != null || outputStream != null)
return; return;
try { new Thread(() -> {
try(Socket client = new Socket("baseband.com.de", 40000)) { try {
client.setSoTimeout(7000); try (Socket client = new Socket("baseband.com.de", 40000)) {
client.getOutputStream().write(1); // client mode client.setSoTimeout(7000);
inputStream = new TypedInputStream(client.getInputStream()); client.getOutputStream().write(1); // client mode
outputStream = new TypedOutputStream(client.getOutputStream()); inputStream = new TypedInputStream(client.getInputStream());
outputStream = new TypedOutputStream(client.getOutputStream());
TCN init = new TCN(); TCN init = new TCN();
init.set("username", LoadHandler.data.getString("username")); init.set("username", LoadHandler.data.getString("username"));
init.set("type", "init"); init.set("type", "init");
init.set("branch", LoadHandler.data.getString("branch")); init.set("branch", LoadHandler.data.getString("branch"));
outputStream.writeString(JSON.write(init)); outputStream.writeString(JSON.write(init));
int fails = 0; int fails = 0;
while (fails < 3) { while (fails < 3) {
try {
String string = inputStream.readString();
if(string.equals("SHUTDOWN."))
BaseBand.shutdown();
TCN packet = JSON.read(string);
fails = 0;
wasEverConnected = true;
handlePacket(packet);
} catch (Exception e) {
fails++;
TCN keepAlive = new TCN();
keepAlive.set("type", "c-keepalive");
try { try {
outputStream.writeString(JSON.write(keepAlive)); String string = inputStream.readString();
} catch (Exception e1) { if (string.equals("SHUTDOWN."))
break; BaseBand.shutdown();
TCN packet = JSON.read(string);
fails = 0;
wasEverConnected = true;
handlePacket(packet);
} catch (Exception e) {
fails++;
TCN keepAlive = new TCN();
keepAlive.set("type", "c-keepalive");
try {
outputStream.writeString(JSON.write(keepAlive));
} catch (Exception e1) {
break;
}
} }
} }
} }
} catch (IOException e) {
if (!wasEverConnected) {
BaseBand.LOGGER.fatal(e);
BaseBand.shutdown();
}
} }
} catch (IOException e) { inputStream = null;
if(!wasEverConnected) { outputStream = null;
BaseBand.LOGGER.fatal(e); }, "WebServiceClient").start();
BaseBand.shutdown();
}
}
inputStream = null;
outputStream = null;
} }
public static boolean outdated = false; public static boolean outdated = false;