-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathProtocol.java
More file actions
17 lines (15 loc) · 853 Bytes
/
Copy pathMathProtocol.java
File metadata and controls
17 lines (15 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class MathProtocol {
// Protocol constants used by both client and server for message parsing
public static final String CONNECT = "CONNECT";
public static final String ACK = "SUCCESS_ACK"; // Acknowledgement sent by server on successful connection
public static final String MATH_REQ = "MATH_REQ";
public static final String CLOSE = "CLOSE";
public static final String RESULT = "RESULT";
public static final String ERROR = "ERROR"; // Server sends this when operation is invalid
// Separator used to split message fields during parsing
public static final String SEPARATOR = ":";
// Message format: MATH_REQ:OPERATOR:NUM1:NUM2 (e.g. MATH_REQ:ADD:10:20)
public static String buildMathRequest(String op, int a, int b) {
return MATH_REQ + SEPARATOR + op + SEPARATOR + a + SEPARATOR + b;
}
}