From 5c55999771fdfa7b492db29f4d5815e0e71d95ee Mon Sep 17 00:00:00 2001 From: pixtaded Date: Sun, 12 Jan 2025 04:00:34 +0300 Subject: [PATCH] Revamp network logic. Closes #2 --- src/main/java/net/pixtaded/crab/client/CrabClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pixtaded/crab/client/CrabClient.java b/src/main/java/net/pixtaded/crab/client/CrabClient.java index 6355e80..4336866 100644 --- a/src/main/java/net/pixtaded/crab/client/CrabClient.java +++ b/src/main/java/net/pixtaded/crab/client/CrabClient.java @@ -38,7 +38,6 @@ public class CrabClient implements Crab { try { if (this.serverAddress == null) setup(); - connect(); communicate(); } catch (IOException e) { System.err.println("Error connecting to the server: " + e.getMessage()); @@ -97,12 +96,14 @@ public class CrabClient implements Crab { } private void sendPacket(byte PID, String argument) throws IOException { + connect(); String formattedMessage = String.valueOf((char) PID) + argument + "\n"; out.print(formattedMessage); out.flush(); receiveResponse(PID); + closeConnection(); } private void receiveResponse(byte PID) throws IOException { @@ -121,8 +122,6 @@ public class CrabClient implements Crab { } default -> { } } - closeConnection(); - connect(); } private void closeConnection() {