// puis établie les chaînages de flot nécessaires
// pour l'envoi et la reception de messages
sock = new Socket(adresseIPServeur, portServeur);
- InputStream IStream = null;
- IStream = sock.getInputStream();
- InputStreamReader IMesg = new InputStreamReader(IStream);
- lecture = new BufferedReader(IMesg);
- OutputStream OStream = null;
- OStream = sock.getOutputStream();
+ OutputStream OStream = sock.getOutputStream();
ecriture = new PrintWriter(OStream);
+
+ InputStream IStream = sock.getInputStream();
+ InputStreamReader IMesg = new InputStreamReader(IStream);
+ lecture = new BufferedReader(IMesg);
}
private void attributesInit() {
while (!end) {
String rline = client.receiveMsg();
if (rline.equals(".")) {
- end = true;
+ end = true;
}
System.out.println(Thread.currentThread().getName() + " a recu " + rline);
}
boolean end = false;
while (!end) {
String line = userInput.readLine();
- if (line.equals(".")) {
+ if (line.equals(".")) {
end = true;
}
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);
+ }
+ }
}
}
}
while (!end) {
Message roMsg = client.receiveoMsg();
if (roMsg.getTexte().equals(".")) {
- end = true;
+ end = true;
}
System.out.println(Thread.currentThread().getName() + " a recu " + roMsg);
}
public class ThreadClientoSend implements Runnable {
private SocketClient client;
//FIXME: use a random name by thread for now
- // should setable
+ // should be setable
private String randName;
ThreadClientoSend(SocketClient c) {
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;
}
Message oMsg = new Message(randName, line, Calendar.getInstance());
}
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);
+ }
+ }
}
}
}