From: Jérôme Benoit Date: Fri, 16 Mar 2018 17:46:10 +0000 (+0100) Subject: TD2: Simplify the object serialization trough socket. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1a8b0826b5021061a361550b8a83cde7c25955cb;p=TD_SR.git TD2: Simplify the object serialization trough socket. Signed-off-by: Jérôme Benoit --- diff --git a/TD2/IHM/SocketClient.java b/TD2/IHM/SocketClient.java index 92c7412..d6db15d 100644 --- a/TD2/IHM/SocketClient.java +++ b/TD2/IHM/SocketClient.java @@ -37,6 +37,20 @@ public class SocketClient { } } + public SocketClient(boolean withoStream) { + // établie une connexion au serveur par un appel + // à connexionServeur() + attributesInit(); + try { + connexionServeur("localhost", 5000, withoStream); + } + catch (IOException e) { + System.err.println("IOException: " + e); + e.printStackTrace(); + closeRWIO(); + } + } + private void connexionServeur(String adresseIPServeur, int portServeur, boolean hasoStream) throws IOException { // créer un objet socket lié au socket serveur et l'affecte à sock // puis établie les chaînages de flot nécessaires diff --git a/TD2/IHM/ThreadIHMSend.java b/TD2/IHM/ThreadIHMSend.java index f173996..2b1a64a 100644 --- a/TD2/IHM/ThreadIHMSend.java +++ b/TD2/IHM/ThreadIHMSend.java @@ -10,7 +10,6 @@ public class ThreadIHMSend implements Runnable { } public void run() { - BufferedReader userInput = null; try { boolean end = false; while (!end) { diff --git a/TD2/client/Main.java b/TD2/client/Main.java index 08300b7..bd02ad4 100644 --- a/TD2/client/Main.java +++ b/TD2/client/Main.java @@ -78,7 +78,7 @@ public class Main { Thread thR = null; try { - client = new SocketClient(); + client = new SocketClient(true); thS = new Thread(new ThreadClientoSend(client)); thR = new Thread(new ThreadClientoReceive(client)); thS.setName("thoS"); diff --git a/TD2/client/SocketClient.java b/TD2/client/SocketClient.java index 92c7412..15ed279 100644 --- a/TD2/client/SocketClient.java +++ b/TD2/client/SocketClient.java @@ -23,6 +23,20 @@ public class SocketClient { } } + public SocketClient(boolean withoStream) { + // établie une connexion au serveur par un appel + // à connexionServeur() + attributesInit(); + try { + connexionServeur("localhost", 5000, withoStream); + } + catch (IOException e) { + System.err.println("IOException: " + e); + e.printStackTrace(); + closeRWIO(); + } + } + public SocketClient(String adresseIPServeur, int portServeur) { // établie une connexion au serveur par un appel // à connexionServeur() diff --git a/TD2/server/Main.java b/TD2/server/Main.java index c951e81..ab04922 100644 --- a/TD2/server/Main.java +++ b/TD2/server/Main.java @@ -5,15 +5,16 @@ public class Main { public static void main(String[] args) { ServerSocket listenSocket = null; try { + int servPort = Integer.parseInt(args[0]); System.out.println("Demarrage du serveur sur le port " - + Integer.parseInt(args[0]) + " et en attente de connexion :"); - listenSocket = new ServerSocket(Integer.parseInt(args[0])); // port + + servPort + " et en attente de connexion :"); + listenSocket = new ServerSocket(servPort); // port while (true) { // le dispatcher est le thread qui execute main() Socket clientSocket = listenSocket.accept(); System.out.println("Connexion de :" + clientSocket.getInetAddress()); //Launch the text broadcasting server Thread serviceThread = new Thread(new BroadcastThreadService(clientSocket)); - //Or lauch the object broadcasting server + //Or launch the object broadcasting server //Thread serviceThread = new Thread(new BroadcastoThreadService(clientSocket)); serviceThread.start(); }