Chat works.
This commit is contained in:
parent
63a8e21f6c
commit
d2c2ca1732
@ -10,13 +10,13 @@ public class JClientProtocolParser {
|
||||
* @param c this Client(required so this method can access the Client's methods)
|
||||
*/
|
||||
public static void parse(String msg, Client c) {
|
||||
String header = ""; //"header" is the first 5 characters.
|
||||
String header = ""; //"header" is the first 5 characters, i.e. the protocol part
|
||||
try {
|
||||
header = msg.substring(0, 5);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(header);
|
||||
//System.out.println(header); helpful for debugging
|
||||
switch (header) {
|
||||
case "SPING":
|
||||
c.sendMsgToServer("PINGB");
|
||||
@ -24,6 +24,9 @@ public class JClientProtocolParser {
|
||||
case "PINGB":
|
||||
c.clientPinger.setGotPingBack(true);
|
||||
break;
|
||||
case "CHATM":
|
||||
System.out.println(msg.substring(6));
|
||||
break;
|
||||
default:
|
||||
System.out.println("Received unknown command");
|
||||
}
|
||||
|
||||
@ -102,9 +102,9 @@ public class ClientHandler implements Runnable {
|
||||
for (ClientHandler client : connectedClients) {
|
||||
try {
|
||||
if (!client.clientUserName.equals((clientUserName))) {
|
||||
client.out.write(msg);
|
||||
client.out.write("CHATM:" + msg);
|
||||
} else {
|
||||
client.out.write("Message: **" + msg + "** sent!");
|
||||
client.out.write("CHATM:Message: **" + msg + "** sent!");
|
||||
}
|
||||
client.out.newLine();
|
||||
client.out.flush();
|
||||
|
||||
@ -11,13 +11,13 @@ public class JServerProtocolParser {
|
||||
* @param h this ClientHandler (required so this method can access the ClientHandler's methods)
|
||||
*/
|
||||
public static void parse(String msg, ClientHandler h) {
|
||||
String header = ""; //"header" is the first 5 characters.
|
||||
String header = ""; //"header" is the first 5 characters, i.e. the protocol part
|
||||
try {
|
||||
header = msg.substring(0, 5);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(header);
|
||||
//System.out.println(header); helpful for debugging
|
||||
switch (header) {
|
||||
case "CHATA":
|
||||
h.broadcastMessage(msg.substring(6));
|
||||
|
||||
Reference in New Issue
Block a user