repositories
/
TD_SR.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TD2: Be more informative at exception catching.
[TD_SR.git]
/
TD2
/
client
/
SocketClient.java
diff --git
a/TD2/client/SocketClient.java
b/TD2/client/SocketClient.java
index b8e0c0b35491a30ae89bde0908b34ecbfb680697..75c04703064caf9ff2ecc9a8ea5c958b84708993 100644
(file)
--- a/
TD2/client/SocketClient.java
+++ b/
TD2/client/SocketClient.java
@@
-5,6
+5,8
@@
import java.util.*;
public class SocketClient {
BufferedReader lecture; // pour le flot d'entrée venant du serveur
PrintWriter ecriture; // pour le flot de sortie vers le serveur
public class SocketClient {
BufferedReader lecture; // pour le flot d'entrée venant du serveur
PrintWriter ecriture; // pour le flot de sortie vers le serveur
+ ObjectInput oLecture;
+ ObjectOutput oEcriture;
Socket sock; // le socket client
public SocketClient() {
Socket sock; // le socket client
public SocketClient() {
@@
-16,6
+18,7
@@
public class SocketClient {
}
catch (IOException e) {
System.err.println("IOException: " + e);
}
catch (IOException e) {
System.err.println("IOException: " + e);
+ e.printStackTrace();
closeRWIO();
}
}
closeRWIO();
}
}
@@
-29,6
+32,7
@@
public class SocketClient {
}
catch (IOException e) {
System.err.println("IOException: " + e);
}
catch (IOException e) {
System.err.println("IOException: " + e);
+ e.printStackTrace();
closeRWIO();
}
}
closeRWIO();
}
}
@@
-38,20
+42,23
@@
public class SocketClient {
// puis établie les chaînages de flot nécessaires
// pour l'envoi et la reception de messages
sock = new Socket(adresseIPServeur, portServeur);
// 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);
ecriture = new PrintWriter(OStream);
+ oEcriture = new ObjectOutputStream(OStream);
+
+ InputStream IStream = sock.getInputStream();
+ InputStreamReader IMesg = new InputStreamReader(IStream);
+ lecture = new BufferedReader(IMesg);
+ oLecture = new ObjectInputStream(IStream);
}
private void attributesInit() {
}
private void attributesInit() {
+ sock = null;
lecture = null;
ecriture = null;
lecture = null;
ecriture = null;
- sock = null;
+ oLecture = null;
+ oEcriture = null;
}
/**
}
/**
@@
-63,17
+70,34
@@
public class SocketClient {
ecriture.flush();
}
ecriture.flush();
}
+ /**
+ * Send an object message on the opened client socket
+ * @param msg a string containing the message to send
+ */
+ public void sendoMsg(Message oMsg) throws IOException {
+ oEcriture.writeObject(oMsg);
+ oEcriture.flush();
+ }
+
/**
* Receive a message sent on the opened client socket
* @return a string containing the received message
*/
public String receiveMsg() throws IOException {
String line = new String();
/**
* Receive a message sent on the opened client socket
* @return a string containing the received message
*/
public String receiveMsg() throws IOException {
String line = new String();
- //FIXME: read only the line before the ending newline
+ //FIXME
?
: read only the line before the ending newline
line = lecture.readLine();
return line;
}
line = lecture.readLine();
return line;
}
+ /**
+ * Receive an object message sent on the opened client socket
+ * @return a string containing the received message
+ */
+ public Message receiveoMsg() throws IOException, ClassNotFoundException {
+ return (Message)oLecture.readObject();
+ }
+
/**
* Close all opened I/O streams attached to this object instance
*/
/**
* Close all opened I/O streams attached to this object instance
*/
@@
-85,9
+109,15
@@
public class SocketClient {
lecture.close();
if (ecriture != null)
ecriture.close();
lecture.close();
if (ecriture != null)
ecriture.close();
+ if (oLecture != null)
+ oLecture.close();
+ if (oEcriture != null) {
+ oEcriture.close();
+ }
}
catch (IOException e) {
System.err.println("IOException: " + e);
}
catch (IOException e) {
System.err.println("IOException: " + e);
+ e.printStackTrace();
}
}
}
}