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.net.Socket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static controllers.Database.getAccount;
|
import static controllers.Database.*;
|
||||||
import static controllers.Database.registerAccount;
|
|
||||||
|
|
||||||
public class ServerThread extends Thread {
|
public class ServerThread extends Thread {
|
||||||
private final Socket client;
|
private final Socket client;
|
||||||
@ -97,14 +96,21 @@ public class ServerThread extends Thread {
|
|||||||
|
|
||||||
MessageForwarder.addUser(clientId, this);
|
MessageForwarder.addUser(clientId, this);
|
||||||
|
|
||||||
int recipientId;
|
String message,dUsername;
|
||||||
String message;
|
|
||||||
|
|
||||||
|
sendEncrypted("Inserisci l'username del destinatario: ");
|
||||||
|
try {
|
||||||
|
dUsername = rsa.decrypt(fromClient.readLine());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
int recipientId = getIdFromUsername(dUsername);
|
||||||
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
sendEncrypted("A chi vuoi inviare un messaggio? ");
|
sendEncrypted("Inserisci messaggio: ");
|
||||||
recipientId = Integer.parseInt(rsa.decrypt(fromClient.readLine()));
|
|
||||||
sendEncrypted("Inserisci il messaggio: ");
|
|
||||||
message = rsa.decrypt(fromClient.readLine());
|
message = rsa.decrypt(fromClient.readLine());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -112,6 +118,17 @@ public class ServerThread extends Thread {
|
|||||||
|
|
||||||
if (message == null || "DISCONNECT".equals(message)) break;
|
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 {
|
try {
|
||||||
MessageForwarder.sendTo(recipientId, message, clientId);
|
MessageForwarder.sendTo(recipientId, message, clientId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user