Nearly finished client side logging
Client/src/logging/ClientLogger.java:
-added printConfiramtion method
Client/src/networking/Client.java:
- swapped out.println with clientLogger.printConfirmation
This commit is contained in:
3
Client/src/META-INF/MANIFEST.MF
Normal file
3
Client/src/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: networking.Client
|
||||
|
||||
@@ -44,4 +44,12 @@ public class ClientLogger {
|
||||
public void printLog(String message, boolean success, LogType logType){
|
||||
this.printLog(message, "server", success, logType);
|
||||
}
|
||||
|
||||
public void printConfirmation(int code){
|
||||
if (code == 200){
|
||||
printLog(" Status: sent!", true, LogType.Log);
|
||||
} else {
|
||||
printLog(" Status: not sent!", false, LogType.Log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package networking;
|
||||
|
||||
import logging.ClientLogger;
|
||||
import logging.LogType;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -18,10 +17,6 @@ public class Client {
|
||||
private String serverName;
|
||||
private boolean success;
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final String ANSI_CYAN = "\u001B[36m";
|
||||
|
||||
|
||||
public Client(String ip, int port, String name) {
|
||||
try {
|
||||
scanner = new Scanner(System.in);
|
||||
@@ -39,13 +34,12 @@ public class Client {
|
||||
|
||||
public void handshake() {
|
||||
try {
|
||||
out.writeInt(15315);
|
||||
out.writeInt(165313125);
|
||||
out.flush();
|
||||
success = in.readInt() == 200;
|
||||
if (success){
|
||||
out.writeUTF(name);
|
||||
serverName = in.readUTF();
|
||||
System.out.println(serverName);
|
||||
clientLogger.printLog("You successfully connected to me", serverName, success, LogType.Log);
|
||||
} else {
|
||||
clientLogger.printLog("Connection failed try again", success, LogType.Log);
|
||||
@@ -62,9 +56,11 @@ public class Client {
|
||||
String message = scanner.nextLine();
|
||||
try {
|
||||
out.writeUTF(message);
|
||||
System.out.println(in.readInt());
|
||||
clientLogger.printConfirmation(in.readInt());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
if(message.equalsIgnoreCase("exit()"))
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user