Formatting of how chat messages are displayed, too short a protocol message doesnt print exception stack trace.

This commit is contained in:
Jonas 2022-03-27 13:29:02 +02:00
parent 6071ea4b2f
commit 141a4783b9
5 changed files with 6 additions and 21 deletions

View File

@ -14,7 +14,7 @@ public class JClientProtocolParser {
try { try {
header = msg.substring(0, 5); header = msg.substring(0, 5);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
e.printStackTrace(); System.out.println("Received unknown command");
} }
//System.out.println(header); helpful for debugging //System.out.println(header); helpful for debugging
switch (header) { switch (header) {

View File

@ -50,9 +50,7 @@ public class ClientPinger implements Runnable {
} }
} }
isConnected = false; //in case the socket accidentally disconnects (can this happen?) isConnected = false; //in case the socket accidentally disconnects (can this happen?)
} catch (InterruptedException e) { } catch (InterruptedException | IOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -50,9 +50,7 @@ public class ServerPinger implements Runnable {
} }
} }
isConnected = false; //in case the socket accidentally disconnects (can this happen?) isConnected = false; //in case the socket accidentally disconnects (can this happen?)
} catch (InterruptedException e) { } catch (InterruptedException | IOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -94,18 +94,7 @@ public class ClientHandler implements Runnable {
public void broadcastMessage(String msg) { public void broadcastMessage(String msg) {
for (ClientHandler client : connectedClients) { for (ClientHandler client : connectedClients) {
try { client.sendMsgToClient("CHATM:" + clientUserName + ": \"" + msg + "\"");
if (!client.clientUserName.equals((clientUserName))) {
client.out.write("CHATM:" + msg);
} else {
client.out.write("CHATM:Message: **" + msg + "** sent!");
}
client.out.newLine();
client.out.flush();
} catch (IOException e) {
e.printStackTrace();
closeEverything(socket, in, out);
}
} }
} }

View File

@ -14,7 +14,7 @@ public class JServerProtocolParser {
try { try {
header = msg.substring(0, 5); header = msg.substring(0, 5);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
e.printStackTrace(); System.out.println("Received unknown command");
} }
//System.out.println(header); helpful for debugging //System.out.println(header); helpful for debugging
switch (header) { switch (header) {