repositories
/
TD_SR.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TD2: Fix the remaining bugs in the IHM chat client.
[TD_SR.git]
/
TD2
/
server
/
BroadcastoThreadService.java
diff --git
a/TD2/server/BroadcastoThreadService.java
b/TD2/server/BroadcastoThreadService.java
index e8a3622a2d53a7396a8877b22b6830dc7769b661..fb4737cf7c96e69d946982414ea0b6f179af35a8 100644
(file)
--- a/
TD2/server/BroadcastoThreadService.java
+++ b/
TD2/server/BroadcastoThreadService.java
@@
-19,28
+19,37
@@
public class BroadcastoThreadService implements Runnable {
try {
doService(clientSocket, listoWriter);
clientSocket.close();
try {
doService(clientSocket, listoWriter);
clientSocket.close();
- } catch (IOException e) {
+ }
+ catch (IOException e) {
System.err.println("IOException : " + e);
e.printStackTrace();
}
catch (ClassNotFoundException e) {
System.err.println("IOException : " + e);
e.printStackTrace();
}
catch (ClassNotFoundException e) {
- System.err.println("ClassNotFoundException: " + e);
+
System.err.println("ClassNotFoundException: " + e);
e.printStackTrace();
}
finally {
try {
if (this.clientSocket != null)
this.clientSocket.close();
e.printStackTrace();
}
finally {
try {
if (this.clientSocket != null)
this.clientSocket.close();
- } catch (IOException e) {
+ }
+ catch (IOException e) {
System.err.println("IOException : " + e);
e.printStackTrace();
}
}
}
System.err.println("IOException : " + e);
e.printStackTrace();
}
}
}
+ /**
+ * Be careful, this function must be thread-safe
+ * @param clientSocket [description]
+ * @param sharedList [description]
+ * @throws IOException [description]
+ * @throws ClassNotFoundException [description]
+ */
public void doService(Socket clientSocket, ArrayList<ObjectOutputStream> sharedList) throws IOException, ClassNotFoundException {
public void doService(Socket clientSocket, ArrayList<ObjectOutputStream> sharedList) throws IOException, ClassNotFoundException {
- ObjectInputStream OReader = new ObjectInputStream(clientSocket.getInputStream());
ObjectOutputStream OWriter = new ObjectOutputStream(clientSocket.getOutputStream());
ObjectOutputStream OWriter = new ObjectOutputStream(clientSocket.getOutputStream());
+ ObjectInputStream OReader = new ObjectInputStream(clientSocket.getInputStream());
sharedList.add(OWriter);
boolean end = false;
while (!end) {
sharedList.add(OWriter);
boolean end = false;
while (!end) {
@@
-49,13
+58,14
@@
public class BroadcastoThreadService implements Runnable {
end = true; // le thread de service doit terminer
break; // do not broadcast the dot that will close all clients threads
}
end = true; // le thread de service doit terminer
break; // do not broadcast the dot that will close all clients threads
}
+ System.out.println("Broadcasting the message \"" + roMsg + "\" received from " + clientSocket.toString());
broadcastoMsg(roMsg);
}
sharedList.remove(OWriter);
broadcastoMsg(roMsg);
}
sharedList.remove(OWriter);
- if (OReader != null)
- OReader.close();
if (OWriter != null)
OWriter.close();
if (OWriter != null)
OWriter.close();
+ if (OReader != null)
+ OReader.close();
System.out.println("Fin du thread repondant au client, port "
+ clientSocket.getPort());
}
System.out.println("Fin du thread repondant au client, port "
+ clientSocket.getPort());
}