mirror of
https://github.com/LucasVbr/mini-chat.git
synced 2026-05-16 17:21:53 +00:00
Ajout de javadoc TODO terminer les commentaires
This commit is contained in:
+60
-4
@@ -1,3 +1,9 @@
|
||||
/*
|
||||
* Client.java, 06/12/2022
|
||||
* INU Champollion, 2022-2023
|
||||
* pas de copyright, aucun droits
|
||||
*/
|
||||
|
||||
package client;
|
||||
|
||||
import ui.FenetreClient;
|
||||
@@ -5,7 +11,6 @@ import ui.FenetreErreur;
|
||||
import utils.RSA;
|
||||
import utils.ResolutionDeNom;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
@@ -18,22 +23,50 @@ import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Utilisateur Client
|
||||
*
|
||||
* @author Gaël Burguès
|
||||
* @author Laurian Dufrechou
|
||||
* @author Lucàs Vabre
|
||||
*/
|
||||
|
||||
public class Client extends Thread{
|
||||
|
||||
//elements d'un client
|
||||
private final String SERVER_IP;
|
||||
private final int SERVER_PORT;
|
||||
private final FenetreClient fenetre;
|
||||
private String pseudo;
|
||||
|
||||
private final Scanner scanner;
|
||||
private KeyPair clientKeys;
|
||||
private PublicKey serverKey;
|
||||
|
||||
private final Scanner scanner;
|
||||
|
||||
// Sockets de connexion
|
||||
private ObjectInputStream inputStream;
|
||||
private ObjectOutputStream outputStream;
|
||||
|
||||
private ArrayList<String> fileAttenteMessage;
|
||||
|
||||
public Client(String ip, int port) {
|
||||
this.SERVER_IP = ResolutionDeNom.getIPAddress(ip);
|
||||
this.SERVER_PORT = port;
|
||||
this.pseudo = null;
|
||||
this.fenetre = null;
|
||||
|
||||
this.scanner = new Scanner(System.in);
|
||||
this.clientKeys = RSA.genererCle();
|
||||
|
||||
this.fileAttenteMessage = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* ancien object client sans fenetre
|
||||
* @param ip adresse ip du client
|
||||
* @param port numeros de port du client
|
||||
* @param pseudo pseudo du client
|
||||
*/
|
||||
public Client(String ip, int port, String pseudo) {
|
||||
this.SERVER_IP = ResolutionDeNom.getIPAddress(ip);
|
||||
this.SERVER_PORT = port;
|
||||
@@ -46,6 +79,13 @@ public class Client extends Thread{
|
||||
this.fileAttenteMessage = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Object client actuel
|
||||
* @param ip adresse ip du client
|
||||
* @param port numeros de port du client
|
||||
* @param pseudo nom du client
|
||||
* @param fenetre fenetreClient assicié au client
|
||||
*/
|
||||
public Client(String ip, int port, String pseudo, FenetreClient fenetre) {
|
||||
this.SERVER_IP = ResolutionDeNom.getIPAddress(ip);
|
||||
this.SERVER_PORT = port;
|
||||
@@ -103,6 +143,11 @@ public class Client extends Thread{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* envoie la clef client au serveur
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void exchangeKeys() throws IOException, ClassNotFoundException {
|
||||
// Envoie sa clé
|
||||
outputStream.writeObject(clientKeys.getPublic());
|
||||
@@ -111,11 +156,22 @@ public class Client extends Thread{
|
||||
serverKey = (PublicKey) inputStream.readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* envoie un message dans la socket
|
||||
* @param message message a envoyer au serveur
|
||||
* @throws IOException
|
||||
*/
|
||||
public void sendMessage(String message) throws IOException {
|
||||
byte[] messageCrypte = RSA.encrypter(message, serverKey);
|
||||
outputStream.writeObject(messageCrypte);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recupere un message evoye par le serveur
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public String getMessage() throws IOException, ClassNotFoundException {
|
||||
byte[] messageCrypte = (byte[]) inputStream.readObject();
|
||||
return RSA.decrypter(messageCrypte, clientKeys.getPrivate());
|
||||
@@ -123,7 +179,7 @@ public class Client extends Thread{
|
||||
|
||||
/**
|
||||
* Ajoute un message à la file d'attente
|
||||
* @param message
|
||||
* @param message messsage a ajouter a la file
|
||||
*/
|
||||
public void addMessage(String message) {
|
||||
this.fileAttenteMessage.add(message);
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
/*
|
||||
* ListenThread.java, 06/12/2022
|
||||
* INU Champollion, 2022-2023
|
||||
* pas de copyright, aucun droits
|
||||
*/
|
||||
|
||||
package client;
|
||||
|
||||
import ui.FenetreClient;
|
||||
@@ -8,18 +14,36 @@ import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
|
||||
/**
|
||||
* Thread for clients
|
||||
* Écoute des messages du serveur
|
||||
*
|
||||
* @author Gaël Burguès
|
||||
* @author Laurian Dufrechou
|
||||
* @author Lucàs Vabre
|
||||
*/
|
||||
public class ListenThread extends Thread {
|
||||
|
||||
/** Instance du client */
|
||||
private final Client client;
|
||||
|
||||
/** Interface utilisateur du client */
|
||||
private final FenetreClient fenetre;
|
||||
|
||||
/**
|
||||
* Crée un nouveau thread
|
||||
*
|
||||
* @param client Le client lié à cette écoute
|
||||
*/
|
||||
public ListenThread(Client client) {
|
||||
this.client = client;
|
||||
this.fenetre = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object d'ecoute avec fenetre
|
||||
*
|
||||
* @param client client associe à l'ecoute
|
||||
* @param fenetre fenetreClient associe à l'ecoute
|
||||
*/
|
||||
public ListenThread(Client client, FenetreClient fenetre) {
|
||||
this.client = client;
|
||||
this.fenetre = fenetre;
|
||||
@@ -45,7 +69,7 @@ public class ListenThread extends Thread {
|
||||
new FenetreErreur("Connexion perdue", fenetre);
|
||||
fenetre.deconnexion();
|
||||
}
|
||||
}catch (IOException | ClassNotFoundException e) {
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user