-import java.util.concurrent.ThreadLocalRandom;
import java.io.*;
public class ThreadClientSend implements Runnable {
try {
userInput = new BufferedReader(new InputStreamReader(System.in));
boolean end = false;
- while (!end) {
- String line = userInput.readLine();
- if (line.equals(".")) {
+ while (!end) {
+ String line = userInput.readLine();
+ if (line.equals(".")) {
end = true;
}
- client.sendMsg(line);
- System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+ if (!line.isEmpty()) {
+ client.sendMsg(line);
+ System.out.println(Thread.currentThread().getName() + " a envoye " + line);
+ }
}
- }
+ }
catch (IOException e) {
System.err.println("IOException: " + e);
e.printStackTrace();
}
finally {
if (userInput != null) {
- try {
- userInput.close();
- }
- catch (IOException e) {
- System.err.println("IOException: " + e);
- }
- }
+ try {
+ userInput.close();
+ }
+ catch (IOException e) {
+ System.err.println("IOException: " + e);
+ e.printStackTrace();
+ }
+ }
}
}
}