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:
2021-02-15 00:54:14 +01:00
parent 6b3306a416
commit 1942e249b5
8 changed files with 34 additions and 10 deletions

View File

@@ -1,8 +1,8 @@
<component name="ArtifactManager"> <component name="ArtifactManager">
<artifact type="jar" name="Client:jar"> <artifact type="jar" name="Client:jar">
<output-path>$PROJECT_DIR$/out/artifacts/Client_jar</output-path> <output-path>$PROJECT_DIR$/out/artifacts/Client_jar</output-path>
<root id="archive" name="ArcadeMachine.jar"> <root id="archive" name="Client.jar">
<element id="module-output" name="ArcadeMachine" /> <element id="module-output" name="Client" />
</root> </root>
</artifact> </artifact>
</component> </component>

8
.idea/artifacts/Server_jar.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="Server:jar">
<output-path>$PROJECT_DIR$/out/artifacts/Server_jar</output-path>
<root id="archive" name="Server.jar">
<element id="module-output" name="Server" />
</root>
</artifact>
</component>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: networking.Client

View File

@@ -44,4 +44,12 @@ public class ClientLogger {
public void printLog(String message, boolean success, LogType logType){ public void printLog(String message, boolean success, LogType logType){
this.printLog(message, "server", success, 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);
}
}
} }

View File

@@ -2,7 +2,6 @@ package networking;
import logging.ClientLogger; import logging.ClientLogger;
import logging.LogType; import logging.LogType;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -18,10 +17,6 @@ public class Client {
private String serverName; private String serverName;
private boolean success; 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) { public Client(String ip, int port, String name) {
try { try {
scanner = new Scanner(System.in); scanner = new Scanner(System.in);
@@ -39,13 +34,12 @@ public class Client {
public void handshake() { public void handshake() {
try { try {
out.writeInt(15315); out.writeInt(165313125);
out.flush(); out.flush();
success = in.readInt() == 200; success = in.readInt() == 200;
if (success){ if (success){
out.writeUTF(name); out.writeUTF(name);
serverName = in.readUTF(); serverName = in.readUTF();
System.out.println(serverName);
clientLogger.printLog("You successfully connected to me", serverName, success, LogType.Log); clientLogger.printLog("You successfully connected to me", serverName, success, LogType.Log);
} else { } else {
clientLogger.printLog("Connection failed try again", success, LogType.Log); clientLogger.printLog("Connection failed try again", success, LogType.Log);
@@ -62,9 +56,11 @@ public class Client {
String message = scanner.nextLine(); String message = scanner.nextLine();
try { try {
out.writeUTF(message); out.writeUTF(message);
System.out.println(in.readInt()); clientLogger.printConfirmation(in.readInt());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e){
} }
if(message.equalsIgnoreCase("exit()")) if(message.equalsIgnoreCase("exit()"))
break; break;

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: networking.Server

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: networking.Client

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: networking.Server