diff --git a/src/main/java/net/pixtaded/crab/server/ServerThread.java b/src/main/java/net/pixtaded/crab/server/ServerThread.java index 03006e4..2c13324 100644 --- a/src/main/java/net/pixtaded/crab/server/ServerThread.java +++ b/src/main/java/net/pixtaded/crab/server/ServerThread.java @@ -30,10 +30,13 @@ public class ServerThread implements Runnable { public void run() { try { byte[] PID = input.readNBytes(1); + if (PID.length == 0) { + socket.close(); + return; + } switch (PID[0]) { case MESSAGE -> { server.getDb().logMessage(new Date(), socket.getInetAddress().getHostAddress(), new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim()); - socket.close(); } case LOGS -> { respond(server.getDb().getLogs()); } case LOGS_SIZE -> { @@ -42,6 +45,7 @@ public class ServerThread implements Runnable { System.out.println("PID not implemented: " + PID[0]); } } + socket.close(); } catch (Exception e) { throw new RuntimeException(e); } @@ -50,7 +54,6 @@ public class ServerThread implements Runnable { private void respond(byte[] data) throws IOException { socket.getOutputStream().write(data); socket.getOutputStream().flush(); - socket.close(); } private void respond(String utf8) throws IOException {