Formatting of how chat messages are displayed, too short a protocol message doesnt print exception stack trace.
This commit is contained in:
parent
6071ea4b2f
commit
141a4783b9
@ -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) {
|
||||||
|
|||||||
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user