Server functionality restored
This commit is contained in:
parent
30d90f22f2
commit
a4bf914c41
@ -32,7 +32,7 @@ public class ServerThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
byte[] PID = input.readNBytes(1);
|
||||
byte[] PID = readPID();
|
||||
if (PID.length == 0) {
|
||||
socket.close();
|
||||
return;
|
||||
@ -40,7 +40,6 @@ public class ServerThread implements Runnable {
|
||||
switch (PID[0]) {
|
||||
case COMMUNICATION -> {
|
||||
String msg = new String(input.readNBytes(4096), StandardCharsets.UTF_8).trim();
|
||||
if (!msg.isEmpty()) {
|
||||
Date date = new Date();
|
||||
String address = socket.getInetAddress().getHostAddress();
|
||||
|
||||
@ -49,11 +48,10 @@ public class ServerThread implements Runnable {
|
||||
server.cache = new Logs(newContent.getBytes().length, newContent);
|
||||
|
||||
new Thread(new LogDBThread(date, address, msg)).start();
|
||||
}
|
||||
} /* case LOGS -> {
|
||||
respond(server.cache.content());
|
||||
} */ case LOGS_SIZE -> {
|
||||
} case LOGS_SIZE -> {
|
||||
respond(String.valueOf(server.cache.sizeInBytes()));
|
||||
readPID();
|
||||
sendLogs();
|
||||
} default -> {
|
||||
System.out.println("PID not implemented: " + PID[0]);
|
||||
}
|
||||
@ -64,6 +62,14 @@ public class ServerThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] readPID() throws IOException {
|
||||
return input.readNBytes(1);
|
||||
}
|
||||
|
||||
private void sendLogs() throws IOException {
|
||||
respond(server.cache.content());
|
||||
}
|
||||
|
||||
private void respond(byte[] data) throws IOException {
|
||||
socket.getOutputStream().write(data);
|
||||
socket.getOutputStream().flush();
|
||||
|
Loading…
Reference in New Issue
Block a user