From 600fe7dbf5d70b4144b41a4c4a894807cd2d7612 Mon Sep 17 00:00:00 2001 From: CookieDoe Date: Fri, 19 Mar 2021 15:05:37 +0100 Subject: [PATCH 01/10] Ajout du PROTOCOL.md --- specs/CassandreWoj/PROTOCOL.md | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 specs/CassandreWoj/PROTOCOL.md diff --git a/specs/CassandreWoj/PROTOCOL.md b/specs/CassandreWoj/PROTOCOL.md new file mode 100644 index 0000000..27b939a --- /dev/null +++ b/specs/CassandreWoj/PROTOCOL.md @@ -0,0 +1,63 @@ +# Spécifications + +> Auteur : Cassandre Wojciechowski +> +> Date : 19.03.2021 + +**What transport protocol do we use?** + +Nous utilisons le protocole TCP. + +**How does the client find the server (addresses and ports)?** + +Le client trouve le serveur grâce au port utilisé pour le protocole TCP. + +**Who speaks first?** + +Le client envoie le premier message au serveur. + +**What is the sequence of messages exchanged by the client and the server? (flow)** + +Le client envoie une demande de connexion, le serveur lui répond avec un message donnant les opérations supportées. + +Le client envoie ensuite l'opération dont il cherche le résultat. Le serveur effectue le calcul puis le retourne au client. En cas d'erreur, la raison de l'erreur est retournée au client. + +Quand le client souhaite arrêter la connexion, il envoie un message au serveur qui répond avant d'interrompre la connexion. + +**What happens when a message is received from the other party? (semantics)** + +Client : `connection` + +Serveur : `Welcome to CALC. You can choose from the following operations : ADD, MULT.` + +Client : ` compute ADD 3 2` + +Serveur : `result 5` + +Client : `compute MIN 4 2` + +Serveur : `error : operation not recognized` + +Client : `exit` + +Serveur : `bye` + +**What is the syntax of the messages? How we generate and parse them? (syntax)** + +Client : + +- pour se connecter : `connection` + +- pour un calcul : `compute [ADD / MULT] [OP1] [OP2]` +- pour interrompre la connexion : `exit` + +Serveur : + +- en cas de connexion : `Welcome to CALC. You can choose from the following operations : ADD, MULT.` +- après calcul : `result [RESULT]` +- en cas d'erreur : `error : [info about the problem]` +- en cas d'interruption de connexion : `bye` + +**Who closes the connection and when?** + +C'est le client qui interrompt la connexion quand il a terminé les calculs qu'il souhaitait effectuer. \ No newline at end of file From aad7b82573fdd721b8dabc075bf50e9ce8877aaa Mon Sep 17 00:00:00 2001 From: CookieDoe Date: Thu, 25 Mar 2021 09:58:04 +0100 Subject: [PATCH 02/10] =?UTF-8?q?Specs=20r=C3=A9dig=C3=A9es=20Gwen=20+=20C?= =?UTF-8?q?ass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab_TCP_CALC_specs.md | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Lab_TCP_CALC_specs.md diff --git a/Lab_TCP_CALC_specs.md b/Lab_TCP_CALC_specs.md new file mode 100644 index 0000000..cae3c52 --- /dev/null +++ b/Lab_TCP_CALC_specs.md @@ -0,0 +1,123 @@ +# Spécifications + +## 1 Introduction + +### 1.1 Objectifs du protocole + +Le but premier du protocole CALC est de permettre à des clients d'envoyer des opérations arithmétiques sur un serveur de calcul via un réseau TCP/IP. + +Le serveur de calcul va recevoir le calcul à effectuer, le faire et le renvoyer au client. Les opérations supportées à la base seront l'addition et la multiplication. D'autres pourront être implémentées dès que les premières sont opérationnelles. L'ensemble des possibilités est exposée plus loin dans ce document. + +### 1.2 Fonctionnement général + +Le protocole CALC utilise le protocole de transport TCP pour permettre les échanges entre le client et le serveur. Le client trouve le serveur grâce au numéro de port sur lequel il est connecté : nous choisissons le port 2021 comme port par défaut. + +Le client envoie une demande de connexion. En cas d'acceptation, le serveur lui répond en mentionnant l'ensemble des opérations qu'il supporte. Le client continue ensuite à envoyer des messages comportant les opérations acceptées par le serveur et le serveur répond avec les résultats de ces calculs. + +Pour effectuer un calcul, le client envoie le mot `compute` suivi de l'opération à effectuer (`ADD`, `MULT`, ...) et les deux `opérandes` souhaitées. Lorsque le serveur reçoit la requête `compute`, il vérifie si elle est correcte. Si elle l'est, il effectue le calcul et renvoie `result` suivi du résultat. Si la requête est incorrecte, le serveur retourne un message d'erreur `error` suivi du problème détecté. + +Le client décide quand interrompre la communication en envoyant `quit` au serveur. + +## 2 Messages + +Seuls cinq types de messages sont reconnus lors de la communication entre le client et le serveur. Ces messages permettent de gérer simplement les interactions. + +Nous avons choisi : + +- `CONNECTION` +- `CALC` +- `RESULT` +- `ERROR` +- `QUIT` + +Les messages sont encodés avec `utf-8`. Le motif indiquant la fin de la ligne est `END`. + +#### 2.1 CONNECTION + +Le message `CONNECTION` permet d'amorcer la connexion du client au serveur. Avec cette requête, le client signale au serveur qu'il souhaite lui communiquer des opérations à effectuer. + +Le serveur, s'il est disponible, répond au client en indiquant les opérations supportées. + +Exemple : + +Client : `CONNECTION END` + +Serveur : `CONNECTION - Welcome END ` + +Serveur : `Available : ADD, MULT END` + +#### 2.2 CALC + +Le message `CALC` permet au client d'indiquer que la suite de son message comporte un calcul que le serveur doit effectuer. Il doit ensuite préciser l'opération qu'il souhaite faire, ainsi que les deux opérandes nécessaires. + +Le serveur reçoit la requête commençant par `CALC` et lit les caractères suivants pour identifier l'opération et ses opérandes. + +Exemple : + +Client : `CALC ADD 4 5 END` + +#### 2.3 RESULT + +Le message `RESULT` permet au serveur d'indiquer que les caractères suivant sont le résultat de l'opération demandée par le client. + +Exemple : + +Serveur : `RESULT 9 END` + +#### 2.4 ERROR + +Le message `ERROR` permet au serveur de signaler qu'une erreur est survenue. Deux types d'erreurs peuvent être indiqués : soit la première partie du message est erronée (`CALC` est mal écrit ou une autre instruction non reconnue a été entrée), soit l'opération indiquée n'est pas reconnue par le serveur (`MIN` n'est pas implémenté). + +Exemple : + +Client : `CALC MIN 7 3 END ` + +Serveur : `ERROR - no such op END` + +#### 2.5 QUIT + +Lorsque le client ne souhaite plus effectuer d'opérations, il interrompt la connexion au serveur grâce au message `QUIT`. Lorsque le serveur reçoit ce message, il ferme la connexion. + +Exemple : + +Client : `QUIT END` + +## 3 Eléments spécifiques + +### 3.1 Opérations supportées + +Les opérations supportées dans un premier temps par le serveur sont l'addition `ADD` et la multiplication `MULT`. + +### 3.2 Extensibilité + +Après avoir implémenté les opérations de base, nous pourrons étendre le champs des possibles en proposant la soustraction `MIN`, la division `DIV` et les puissances `POW`. + +### 3.3 Traitement d'erreurs + +En cas d'erreur, le traitement du calcul n'est pas effectué et le problème rencontré est identifié (cf. paragraphe 2.4), puis indiqué au client. + +## 4 Exemples + +Client : `CONNECTION END` + +Serveur : `CONNECTION - Welcome END ` + +Serveur : `Available : ADD, MULT END` + +Client : `CALC ADD 7 15 END` + +Serveur : `RESULT 22 END` + +Client : `CALC MULT 3 4 END` + +Serveur : `RESULT 12 END` + +Client : `CALC DIV 6 2 END` + +Serveur : `ERROR - no such op END` + +Client : `HIHI ADD 4 6 END` + +Serveur : `ERROR - no such action END` + +Client : `QUIT` \ No newline at end of file From d6e06dd938ec6a55d645de695022f2ab99140ad9 Mon Sep 17 00:00:00 2001 From: CookieDoe Date: Thu, 25 Mar 2021 10:01:42 +0100 Subject: [PATCH 03/10] modif --- Lab_TCP_CALC_specs.md => specs/CassandreWoj/Lab_TCP_CALC_specs.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Lab_TCP_CALC_specs.md => specs/CassandreWoj/Lab_TCP_CALC_specs.md (100%) diff --git a/Lab_TCP_CALC_specs.md b/specs/CassandreWoj/Lab_TCP_CALC_specs.md similarity index 100% rename from Lab_TCP_CALC_specs.md rename to specs/CassandreWoj/Lab_TCP_CALC_specs.md From c6746c93ad305116f431dc546b551386bb61eba4 Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Thu, 25 Mar 2021 10:37:50 +0100 Subject: [PATCH 04/10] First commit --- .../exerciceProtocol/.idea/workspace.xml | 56 ++++++++++++++ .../exercise-protocol/.idea/.gitignore | 8 ++ .../exercise-protocol/.idea/compiler.xml | 16 ++++ .../exercise-protocol/.idea/encodings.xml | 6 ++ .../.idea/jarRepositories.xml | 20 +++++ .../libraries/Maven__junit_junit_4_11.xml | 13 ++++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ++++ CassandreWoj/exercise-protocol/.idea/misc.xml | 11 +++ .../exercise-protocol/.idea/modules.xml | 8 ++ CassandreWoj/exercise-protocol/.idea/vcs.xml | 6 ++ .../exercise-protocol/exercise-protocol.iml | 16 ++++ CassandreWoj/exercise-protocol/pom.xml | 75 +++++++++++++++++++ .../src/main/java/com/heigvd/App.java | 13 ++++ .../heigvd/Protocol/CalculatorProtocol.java | 4 + .../src/test/java/com/heigvd/AppTest.java | 20 +++++ 15 files changed, 285 insertions(+) create mode 100644 CassandreWoj/exerciceProtocol/.idea/workspace.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/.gitignore create mode 100644 CassandreWoj/exercise-protocol/.idea/compiler.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/encodings.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/jarRepositories.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/misc.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/modules.xml create mode 100644 CassandreWoj/exercise-protocol/.idea/vcs.xml create mode 100644 CassandreWoj/exercise-protocol/exercise-protocol.iml create mode 100644 CassandreWoj/exercise-protocol/pom.xml create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java create mode 100644 CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java diff --git a/CassandreWoj/exerciceProtocol/.idea/workspace.xml b/CassandreWoj/exerciceProtocol/.idea/workspace.xml new file mode 100644 index 0000000..ed0764a --- /dev/null +++ b/CassandreWoj/exerciceProtocol/.idea/workspace.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 1616664544318 + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/.gitignore b/CassandreWoj/exercise-protocol/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/CassandreWoj/exercise-protocol/.idea/compiler.xml b/CassandreWoj/exercise-protocol/.idea/compiler.xml new file mode 100644 index 0000000..dfc2dc4 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/encodings.xml b/CassandreWoj/exercise-protocol/.idea/encodings.xml new file mode 100644 index 0000000..63e9001 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/jarRepositories.xml b/CassandreWoj/exercise-protocol/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml new file mode 100644 index 0000000..f33320d --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/misc.xml b/CassandreWoj/exercise-protocol/.idea/misc.xml new file mode 100644 index 0000000..32b0695 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/modules.xml b/CassandreWoj/exercise-protocol/.idea/modules.xml new file mode 100644 index 0000000..d8d44d0 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/vcs.xml b/CassandreWoj/exercise-protocol/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/CassandreWoj/exercise-protocol/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/exercise-protocol.iml b/CassandreWoj/exercise-protocol/exercise-protocol.iml new file mode 100644 index 0000000..3f4fd58 --- /dev/null +++ b/CassandreWoj/exercise-protocol/exercise-protocol.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/pom.xml b/CassandreWoj/exercise-protocol/pom.xml new file mode 100644 index 0000000..87cdb94 --- /dev/null +++ b/CassandreWoj/exercise-protocol/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + com.heigvd + exercise-protocol + 1.0-SNAPSHOT + + exercise-protocol + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java new file mode 100644 index 0000000..28a73fe --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java @@ -0,0 +1,13 @@ +package com.heigvd; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java new file mode 100644 index 0000000..34eca6e --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java @@ -0,0 +1,4 @@ +package com.heigvd.Protocol; + +public class CalculatorProtocol { +} diff --git a/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java b/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java new file mode 100644 index 0000000..cfdc690 --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java @@ -0,0 +1,20 @@ +package com.heigvd; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} From ec50f65a314326d014b280ae2648b116408a80d0 Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Thu, 25 Mar 2021 10:48:21 +0100 Subject: [PATCH 05/10] Protocol message --- .../com/heigvd/Protocol/CalculatorProtocol.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java index 34eca6e..fac8f20 100644 --- a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java @@ -1,4 +1,20 @@ package com.heigvd.Protocol; public class CalculatorProtocol { + public final static int DEFAULT_PORT = 2222; + + public final static String CMD_CONNECTION = "CONNECTION"; + public final static String CMD_CALC = "CALC"; + public final static String CMD_RESULT = "RESULT"; + public final static String CMD_ERROR_UNKNOWN = "ERROR command unknown"; + public final static String CMD_ERROR_BAD = "ERROR bad syntax"; + public final static String CMD_ADD = "ADD"; + public final static String CMD_MULT = "MULT"; + public final static String CMD_QUIT = "QUIT"; + + public final static String CMD_END = "END"; + + public final static String RESPONSE_START = CMD_CONNECTION+" - Welcome " + CMD_END; + public final static String RESPONSE_START2 = "Available: "+CMD_ADD+ " " + CMD_MULT + " " + CMD_END; + public final static String[] SUPPORTED_COMMANDS = new String[]{CMD_CALC,CMD_ADD,CMD_MULT,CMD_QUIT}; } From bdeee86c95215a048a4275f32e46685abc75731f Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Thu, 25 Mar 2021 11:36:00 +0100 Subject: [PATCH 06/10] Premier jet du client --- .../com/heigvd/Client/CalculatorClient.java | 78 +++++++++++++++++++ .../com/heigvd/Client/ICalculatorClient.java | 38 +++++++++ 2 files changed, 116 insertions(+) create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java new file mode 100644 index 0000000..233824e --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java @@ -0,0 +1,78 @@ +package com.heigvd.Client; +import com.heigvd.Protocol.*; +import java.io.*; +import java.net.Socket; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class CalculatorClient implements ICalculatorClient{ + private static final Logger LOG = Logger.getLogger(CalculatorClient.class.getName()); + + Socket socketClient = null; + BufferedReader reader = null; + PrintWriter writer = null; + boolean clientConnected = false; + + @Override + public void connect(String server, int port) throws IOException { + try { + this.socketClient = new Socket(server, port); + this.reader = new BufferedReader(new InputStreamReader(socketClient.getInputStream())); + this.writer = new PrintWriter(socketClient.getOutputStream()); + if (!isConnected()) + throw new IOException("error"); + LOG.log(Level.INFO, "connected to " + server + ':' + port + " ... "); + }catch (IOException e){ + LOG.log(Level.SEVERE, "An error occured during connection to socket : {0}", e.getMessage()); + cleanConnection(); + throw e; + } + } + + protected void cleanConnection() throws IOException{ + try{ + socketClient.close(); + reader.close(); + writer.close(); + clientConnected = false; + }catch (IOException e){ + throw e; + } + } + + + @Override + public void disconnect() throws IOException { + try{ + writer.println(CalculatorProtocol.CMD_QUIT); + writer.flush(); + LOG.log(Level.INFO, "disconnected ... "); + cleanConnection(); + }catch (IOException e) { + LOG.log(Level.INFO, "An error occured during disconnection : {0}", e.getMessage()); + throw e; + } + } + + @Override + public boolean isConnected() { + try{ + //Recupère le Welcome + reader.readLine(); + //ADD LOG + clientConnected = true; + return true; + }catch (IOException e){ + return false; + } + } + + @Override + public void calculate(String calcul) throws IOException { + writer.println(calcul + CalculatorProtocol.CMD_END); + writer.flush(); + reader.readLine(); + LOG.log(Level.INFO, "Calcul-... "); + } +} diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java new file mode 100644 index 0000000..95723f5 --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java @@ -0,0 +1,38 @@ +package com.heigvd.Client; + +import java.io.IOException; +import java.util.List; + +public interface ICalculatorClient { + /** + * Establishes a connection with the server, given its IP address or DNS name + * and its port. + * + * @param server the IP address or DNS name of the servr + * @param port the TCP port on which the server is listening + * @throws java.io.IOException + */ + public void connect(String server, int port) throws IOException; + + /** + * Disconnects from the server by issuing the 'BYE' command. + * + * @throws IOException + */ + public void disconnect() throws IOException; + + /** + * Checks if the client is connected with the server + * + * @return true if the client is connected with the server + */ + public boolean isConnected(); + + /** + * + * + * @return + * @throws IOException + */ + public void calculate(String calcul) throws IOException; +} From 000b4ff8bf6fdb4fa4074ca3265a8885983c19ec Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Thu, 25 Mar 2021 11:50:57 +0100 Subject: [PATCH 07/10] =?UTF-8?q?D=C3=A9but=20serveur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/heigvd/Server/CalculatorServer.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java new file mode 100644 index 0000000..a600760 --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java @@ -0,0 +1,41 @@ +package com.heigvd.Server; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import com.heigvd.Protocol.*; + +public class CalculatorServer { + /* + * The TCP port where client connection requests are accepted. -1 indicates that + * we want to use an ephemeral port number, assigned by the OS + */ + private int listenPort = -1; + + /* + * The server socket, used to accept client connection requests + */ + private ServerSocket serverSocket; + + final static Logger LOG = Logger.getLogger(CalculatorServer.class.getName()); + + public CalculatorServer(int listenPort) { + this.listenPort = listenPort; + } + + public void startServer() throws IOException {} + + /** + * Requests a server shutdown. This will close the server socket and notify + * all client workers. + * + * @throws IOException + */ + public void stopServer() throws IOException { + + } +} From 6f0d25f4ee6bc6fcaa9b2db870e1c8efbbc3f85e Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Fri, 26 Mar 2021 15:26:51 +0100 Subject: [PATCH 08/10] Implementation server en cours --- .../com/heigvd/Server/CalculatorServer.java | 46 +++++++- .../java/com/heigvd/Server/ServantWorker.java | 103 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java index a600760..9a841f0 100644 --- a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java @@ -8,6 +8,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.heigvd.Protocol.*; +import com.heigvd.Server.ServantWorker; public class CalculatorServer { /* @@ -21,13 +22,48 @@ public class CalculatorServer { */ private ServerSocket serverSocket; + /* + * A flag that indicates whether the server should continue to run (or whether + * a shutdown is in progress) + */ + private boolean shouldRun = false; + + /* + * The server maintains a list of client workers, so that they can be notified + * when the server shuts down + */ + List servantWorkers = new CopyOnWriteArrayList<>(); + final static Logger LOG = Logger.getLogger(CalculatorServer.class.getName()); public CalculatorServer(int listenPort) { this.listenPort = listenPort; } - public void startServer() throws IOException {} + public void startServer() throws IOException { + try{ + ServerSocket serverSocket = new ServerSocket(listenPort); + shouldRun = true; + }catch(IOException e) { + LOG.log(Level.SEVERE, null, e); + return; + } + + while (shouldRun){ + LOG.log(Level.INFO, "Waiting for a new client"); + try{ + Socket clientSocket = serverSocket.accept(); + LOG.info("A new client has arrived..."); + ServantWorker worker = new ServantWorker(clientSocket, this); + servantWorkers.add(worker); + new Thread(worker).start(); + }catch (IOException e){ + LOG.log(Level.SEVERE, e.getMessage(), e); + shouldRun = false; + } + } + + } /** * Requests a server shutdown. This will close the server socket and notify @@ -36,6 +72,14 @@ public void startServer() throws IOException {} * @throws IOException */ public void stopServer() throws IOException { + shouldRun = false; + serverSocket.close(); + for (ServantWorker worker : servantWorkers) { + worker.notifyWorkerShutdown(); + } + } + public void notifyWorkerDone(ServantWorker worker){ + servantWorkers.remove(worker); } } diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java new file mode 100644 index 0000000..2931312 --- /dev/null +++ b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java @@ -0,0 +1,103 @@ +package com.heigvd.Server; +import com.heigvd.Protocol.*; + +import com.heigvd.Protocol.CalculatorProtocol; +import jdk.jfr.FlightRecorder; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ServantWorker implements Runnable{ + Socket clientSocket; + CalculatorServer server; + final static Logger LOG = Logger.getLogger(ServantWorker.class.getName()); + + /* + * A flag that indicates whether the server should continue to run (or whether + * a shutdown is in progress) + */ + private boolean shouldRun = false; + + public ServantWorker( Socket clientSocket, CalculatorServer server ) throws IOException { + this.clientSocket = clientSocket; + this.server = server; + this.reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + this.writer = new PrintWriter(clientSocket.getOutputStream()); + shouldRun = true; + } + + BufferedReader reader = null; + PrintWriter writer = null; + + + public String calculate(String operation, int op1, int op2) throws IOException { + String result = CalculatorProtocol.CMD_RESULT + " " ; + switch(operation){ + case CalculatorProtocol.CMD_MULT: + result += Integer.toString(op1 * op2); + break; + case CalculatorProtocol.CMD_ADD: + result += Integer.toString(op1 + op2); + break; + default: + result = CalculatorProtocol.CMD_ERROR_BAD; + } + return result; + } + + + + + + + public void notifyWorkerShutdown() { + try { + reader.close(); + writer.close(); + + } catch (IOException ex) { + LOG.log(Level.INFO, "Exception while closing input or output stream on the server: {0}", ex.getMessage()); + } + + try { + clientSocket.close(); + } catch (IOException ex) { + LOG.log(Level.INFO, "Exception while closing socket on the server: {0}", ex.getMessage()); + } + server.notifyWorkerDone(this); + } + + @Override + public void run() { + String blabla = null; + String[] command = null; + writer.println(CalculatorProtocol.RESPONSE_START); + writer.flush(); + writer.println(CalculatorProtocol.RESPONSE_START2); + writer.flush(); + try { + while(shouldRun){ + blabla = reader.readLine(); + command = blabla.split(" "); + if(command[0].equals(CalculatorProtocol.CMD_CALC)) + + if(command[0].equals(CalculatorProtocol.)) + + if(blabla.equals(CalculatorProtocol.CMD_QUIT)){ + shouldRun = false; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + notifyWorkerShutdown(); + server.notifyWorkerDone(this); + + } +} From 553cc92d455492cda3818ebfa67dca768803afca Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Fri, 26 Mar 2021 16:33:57 +0100 Subject: [PATCH 09/10] =?UTF-8?q?Impl=C3=A9mentation=20en=20cours=20x2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.name | 1 + .../.idea => .idea}/compiler.xml | 0 .../.idea => .idea}/encodings.xml | 0 .../.idea => .idea}/jarRepositories.xml | 0 ...Maven__org_projectlombok_lombok_1_18_2.xml | 13 ++++ .../.idea => .idea}/misc.xml | 0 .../.idea => .idea}/modules.xml | 0 .../exercise-protocol/.idea => .idea}/vcs.xml | 2 +- .idea/workspace.xml | 65 ++++++++++++++++ .../exerciceProtocol/.idea/workspace.xml | 56 -------------- .../exercise-protocol/.idea/.gitignore | 8 -- .../libraries/Maven__junit_junit_4_11.xml | 13 ---- .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 ---- CassandreWoj/exercise-protocol/pom.xml | 75 ------------------- .../src/main/java/com/heigvd/App.java | 13 ---- .../src/test/java/com/heigvd/AppTest.java | 20 ----- ...cise-protocol.iml => exercise-protocol.iml | 4 +- pom.xml | 51 +++++++++++++ src/main/java/com/heigvd/App.java | 27 +++++++ .../com/heigvd/Client/CalculatorClient.java | 0 .../com/heigvd/Client/ICalculatorClient.java | 0 .../heigvd/Protocol/CalculatorProtocol.java | 0 .../com/heigvd/Server/CalculatorServer.java | 0 .../java/com/heigvd/Server/ServantWorker.java | 23 +++--- 24 files changed, 172 insertions(+), 212 deletions(-) create mode 100644 .idea/.name rename {CassandreWoj/exercise-protocol/.idea => .idea}/compiler.xml (100%) rename {CassandreWoj/exercise-protocol/.idea => .idea}/encodings.xml (100%) rename {CassandreWoj/exercise-protocol/.idea => .idea}/jarRepositories.xml (100%) create mode 100644 .idea/libraries/Maven__org_projectlombok_lombok_1_18_2.xml rename {CassandreWoj/exercise-protocol/.idea => .idea}/misc.xml (100%) rename {CassandreWoj/exercise-protocol/.idea => .idea}/modules.xml (100%) rename {CassandreWoj/exercise-protocol/.idea => .idea}/vcs.xml (68%) create mode 100644 .idea/workspace.xml delete mode 100644 CassandreWoj/exerciceProtocol/.idea/workspace.xml delete mode 100644 CassandreWoj/exercise-protocol/.idea/.gitignore delete mode 100644 CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml delete mode 100644 CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml delete mode 100644 CassandreWoj/exercise-protocol/pom.xml delete mode 100644 CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java delete mode 100644 CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java rename CassandreWoj/exercise-protocol/exercise-protocol.iml => exercise-protocol.iml (69%) create mode 100644 pom.xml create mode 100644 src/main/java/com/heigvd/App.java rename {CassandreWoj/exercise-protocol/src => src}/main/java/com/heigvd/Client/CalculatorClient.java (100%) rename {CassandreWoj/exercise-protocol/src => src}/main/java/com/heigvd/Client/ICalculatorClient.java (100%) rename {CassandreWoj/exercise-protocol/src => src}/main/java/com/heigvd/Protocol/CalculatorProtocol.java (100%) rename {CassandreWoj/exercise-protocol/src => src}/main/java/com/heigvd/Server/CalculatorServer.java (100%) rename {CassandreWoj/exercise-protocol/src => src}/main/java/com/heigvd/Server/ServantWorker.java (84%) diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..c5681ba --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +exercise-protocol \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/compiler.xml b/.idea/compiler.xml similarity index 100% rename from CassandreWoj/exercise-protocol/.idea/compiler.xml rename to .idea/compiler.xml diff --git a/CassandreWoj/exercise-protocol/.idea/encodings.xml b/.idea/encodings.xml similarity index 100% rename from CassandreWoj/exercise-protocol/.idea/encodings.xml rename to .idea/encodings.xml diff --git a/CassandreWoj/exercise-protocol/.idea/jarRepositories.xml b/.idea/jarRepositories.xml similarity index 100% rename from CassandreWoj/exercise-protocol/.idea/jarRepositories.xml rename to .idea/jarRepositories.xml diff --git a/.idea/libraries/Maven__org_projectlombok_lombok_1_18_2.xml b/.idea/libraries/Maven__org_projectlombok_lombok_1_18_2.xml new file mode 100644 index 0000000..638f01b --- /dev/null +++ b/.idea/libraries/Maven__org_projectlombok_lombok_1_18_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/misc.xml b/.idea/misc.xml similarity index 100% rename from CassandreWoj/exercise-protocol/.idea/misc.xml rename to .idea/misc.xml diff --git a/CassandreWoj/exercise-protocol/.idea/modules.xml b/.idea/modules.xml similarity index 100% rename from CassandreWoj/exercise-protocol/.idea/modules.xml rename to .idea/modules.xml diff --git a/CassandreWoj/exercise-protocol/.idea/vcs.xml b/.idea/vcs.xml similarity index 68% rename from CassandreWoj/exercise-protocol/.idea/vcs.xml rename to .idea/vcs.xml index b2bdec2..94a25f7 100644 --- a/CassandreWoj/exercise-protocol/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e88bb68 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1616772784953 + + + + + + \ No newline at end of file diff --git a/CassandreWoj/exerciceProtocol/.idea/workspace.xml b/CassandreWoj/exerciceProtocol/.idea/workspace.xml deleted file mode 100644 index ed0764a..0000000 --- a/CassandreWoj/exerciceProtocol/.idea/workspace.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - 1616664544318 - - - - - - - - - \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/.gitignore b/CassandreWoj/exercise-protocol/.idea/.gitignore deleted file mode 100644 index 73f69e0..0000000 --- a/CassandreWoj/exercise-protocol/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml deleted file mode 100644 index f33320d..0000000 --- a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__junit_junit_4_11.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml deleted file mode 100644 index f58bbc1..0000000 --- a/CassandreWoj/exercise-protocol/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/CassandreWoj/exercise-protocol/pom.xml b/CassandreWoj/exercise-protocol/pom.xml deleted file mode 100644 index 87cdb94..0000000 --- a/CassandreWoj/exercise-protocol/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - com.heigvd - exercise-protocol - 1.0-SNAPSHOT - - exercise-protocol - - http://www.example.com - - - UTF-8 - 1.7 - 1.7 - - - - - junit - junit - 4.11 - test - - - - - - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - maven-site-plugin - 3.7.1 - - - maven-project-info-reports-plugin - 3.0.0 - - - - - diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java b/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java deleted file mode 100644 index 28a73fe..0000000 --- a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.heigvd; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} diff --git a/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java b/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java deleted file mode 100644 index cfdc690..0000000 --- a/CassandreWoj/exercise-protocol/src/test/java/com/heigvd/AppTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.heigvd; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} diff --git a/CassandreWoj/exercise-protocol/exercise-protocol.iml b/exercise-protocol.iml similarity index 69% rename from CassandreWoj/exercise-protocol/exercise-protocol.iml rename to exercise-protocol.iml index 3f4fd58..f29851c 100644 --- a/CassandreWoj/exercise-protocol/exercise-protocol.iml +++ b/exercise-protocol.iml @@ -5,12 +5,10 @@ - - - + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6c283d7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + com.heigvd + exercise-protocol + 1.0-SNAPSHOT + jar + + UTF-8 + 1.7 + 1.7 + + + exercise-protocol + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + + + com.heigvd.App + + + + + + + + + + + + org.projectlombok + lombok + 1.18.2 + provided + + + diff --git a/src/main/java/com/heigvd/App.java b/src/main/java/com/heigvd/App.java new file mode 100644 index 0000000..71ef696 --- /dev/null +++ b/src/main/java/com/heigvd/App.java @@ -0,0 +1,27 @@ +package com.heigvd; + +import com.heigvd.Client.CalculatorClient; +import com.heigvd.Server.CalculatorServer; + +import java.io.IOException; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) throws IOException { + System.out.println( "Hello World!" ); + int port = 2222; + String ip = "192.168.1.107"; + + CalculatorServer server = new CalculatorServer(port); + server.startServer(); + + CalculatorClient client1 = new CalculatorClient(); + //CalculatorClient client2 = new CalculatorClient(); + client1.connect(ip,port); + + } +} diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java b/src/main/java/com/heigvd/Client/CalculatorClient.java similarity index 100% rename from CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/CalculatorClient.java rename to src/main/java/com/heigvd/Client/CalculatorClient.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java b/src/main/java/com/heigvd/Client/ICalculatorClient.java similarity index 100% rename from CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Client/ICalculatorClient.java rename to src/main/java/com/heigvd/Client/ICalculatorClient.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java b/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java similarity index 100% rename from CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Protocol/CalculatorProtocol.java rename to src/main/java/com/heigvd/Protocol/CalculatorProtocol.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java b/src/main/java/com/heigvd/Server/CalculatorServer.java similarity index 100% rename from CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/CalculatorServer.java rename to src/main/java/com/heigvd/Server/CalculatorServer.java diff --git a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java b/src/main/java/com/heigvd/Server/ServantWorker.java similarity index 84% rename from CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java rename to src/main/java/com/heigvd/Server/ServantWorker.java index 2931312..c3f4159 100644 --- a/CassandreWoj/exercise-protocol/src/main/java/com/heigvd/Server/ServantWorker.java +++ b/src/main/java/com/heigvd/Server/ServantWorker.java @@ -50,11 +50,6 @@ public String calculate(String operation, int op1, int op2) throws IOException { return result; } - - - - - public void notifyWorkerShutdown() { try { reader.close(); @@ -84,13 +79,21 @@ public void run() { while(shouldRun){ blabla = reader.readLine(); command = blabla.split(" "); - if(command[0].equals(CalculatorProtocol.CMD_CALC)) - - if(command[0].equals(CalculatorProtocol.)) - - if(blabla.equals(CalculatorProtocol.CMD_QUIT)){ + if(command[0].equals(CalculatorProtocol.CMD_CALC)){ + if(command.length == 4) { + writer.println(calculate(command[1], Integer.parseInt(command[2]), Integer.parseInt(command[3]))); + } + else{ + writer.println(CalculatorProtocol.CMD_ERROR_BAD); + } + } + else if (blabla.equals(CalculatorProtocol.CMD_QUIT)){ shouldRun = false; } + else{ + writer.println(CalculatorProtocol.CMD_ERROR_UNKNOWN); + } + writer.flush(); } } catch (IOException e) { e.printStackTrace(); From 28765627d9e1fb62c1668c37c08d859ccdebcc55 Mon Sep 17 00:00:00 2001 From: Dosseggegw1 Date: Mon, 29 Mar 2021 10:43:33 +0200 Subject: [PATCH 10/10] Serveur Ok --- .idea/workspace.xml | 22 +++---------------- src/main/java/com/heigvd/App.java | 4 ---- .../com/heigvd/Server/CalculatorServer.java | 3 ++- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e88bb68..a13d378 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,25 +5,8 @@ - - - - - - - - - - - - - - - - - - - + + diff --git a/src/main/java/com/heigvd/App.java b/src/main/java/com/heigvd/App.java index 71ef696..4b41b0a 100644 --- a/src/main/java/com/heigvd/App.java +++ b/src/main/java/com/heigvd/App.java @@ -19,9 +19,5 @@ public static void main( String[] args ) throws IOException { CalculatorServer server = new CalculatorServer(port); server.startServer(); - CalculatorClient client1 = new CalculatorClient(); - //CalculatorClient client2 = new CalculatorClient(); - client1.connect(ip,port); - } } diff --git a/src/main/java/com/heigvd/Server/CalculatorServer.java b/src/main/java/com/heigvd/Server/CalculatorServer.java index 9a841f0..d40bec4 100644 --- a/src/main/java/com/heigvd/Server/CalculatorServer.java +++ b/src/main/java/com/heigvd/Server/CalculatorServer.java @@ -38,11 +38,12 @@ public class CalculatorServer { public CalculatorServer(int listenPort) { this.listenPort = listenPort; + } public void startServer() throws IOException { try{ - ServerSocket serverSocket = new ServerSocket(listenPort); + this.serverSocket = new ServerSocket(listenPort); shouldRun = true; }catch(IOException e) { LOG.log(Level.SEVERE, null, e);