diff --git a/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java b/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java index 8122031..b834153 100644 --- a/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java +++ b/Client/src/main/java/de/com/baseband/client/util/net/WebServiceClient.java @@ -20,50 +20,52 @@ public class WebServiceClient { public static void connect() { if(inputStream != null || outputStream != null) return; - try { - try(Socket client = new Socket("baseband.com.de", 40000)) { - client.setSoTimeout(7000); - client.getOutputStream().write(1); // client mode - inputStream = new TypedInputStream(client.getInputStream()); - outputStream = new TypedOutputStream(client.getOutputStream()); + new Thread(() -> { + try { + try (Socket client = new Socket("baseband.com.de", 40000)) { + client.setSoTimeout(7000); + client.getOutputStream().write(1); // client mode + inputStream = new TypedInputStream(client.getInputStream()); + outputStream = new TypedOutputStream(client.getOutputStream()); - TCN init = new TCN(); - init.set("username", LoadHandler.data.getString("username")); - init.set("type", "init"); - init.set("branch", LoadHandler.data.getString("branch")); - outputStream.writeString(JSON.write(init)); + TCN init = new TCN(); + init.set("username", LoadHandler.data.getString("username")); + init.set("type", "init"); + init.set("branch", LoadHandler.data.getString("branch")); + outputStream.writeString(JSON.write(init)); - int fails = 0; - 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"); + int fails = 0; + while (fails < 3) { try { - outputStream.writeString(JSON.write(keepAlive)); - } catch (Exception e1) { - break; + 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 { + outputStream.writeString(JSON.write(keepAlive)); + } catch (Exception e1) { + break; + } } } } + } catch (IOException e) { + if (!wasEverConnected) { + BaseBand.LOGGER.fatal(e); + BaseBand.shutdown(); + } } - } catch (IOException e) { - if(!wasEverConnected) { - BaseBand.LOGGER.fatal(e); - BaseBand.shutdown(); - } - } - inputStream = null; - outputStream = null; + inputStream = null; + outputStream = null; + }, "WebServiceClient").start(); } public static boolean outdated = false;