Improved data transfer between client and server
This commit is contained in:
parent
ccbd98dc63
commit
5f6c3de854
@ -9,8 +9,7 @@ import java.math.BigInteger;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static controllers.Database.getAccount;
|
||||
import static controllers.Database.registerAccount;
|
||||
import static controllers.Database.*;
|
||||
|
||||
public class ServerThread extends Thread {
|
||||
private final Socket client;
|
||||
@ -97,14 +96,21 @@ public class ServerThread extends Thread {
|
||||
|
||||
MessageForwarder.addUser(clientId, this);
|
||||
|
||||
int recipientId;
|
||||
String message;
|
||||
String message,dUsername;
|
||||
|
||||
|
||||
sendEncrypted("Inserisci l'username del destinatario: ");
|
||||
try {
|
||||
dUsername = rsa.decrypt(fromClient.readLine());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
int recipientId = getIdFromUsername(dUsername);
|
||||
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
sendEncrypted("A chi vuoi inviare un messaggio? ");
|
||||
recipientId = Integer.parseInt(rsa.decrypt(fromClient.readLine()));
|
||||
sendEncrypted("Inserisci il messaggio: ");
|
||||
sendEncrypted("Inserisci messaggio: ");
|
||||
message = rsa.decrypt(fromClient.readLine());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -112,6 +118,17 @@ public class ServerThread extends Thread {
|
||||
|
||||
if (message == null || "DISCONNECT".equals(message)) break;
|
||||
|
||||
if ("CAMBIA_DESTINATARIO".equals(message)){
|
||||
try {
|
||||
sendEncrypted("Inserisci l'username del nuovo destinatario: ");
|
||||
dUsername = rsa.decrypt(fromClient.readLine());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
recipientId = getIdFromUsername(dUsername);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
MessageForwarder.sendTo(recipientId, message, clientId);
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user