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() {
IStream = sock.getInputStream();
InputStreamReader IMesg = new InputStreamReader(IStream);
lecture = new BufferedReader(IMesg);
+ oLecture = new ObjectInputStream(IStream);
OutputStream OStream = null;
OStream = sock.getOutputStream();
ecriture = new PrintWriter(OStream);
+ oEcriture = new ObjectOutputStream(OStream);
}
private void attributesInit() {
+ sock = null;
lecture = null;
ecriture = null;
- sock = null;
+ oLecture = null;
+ oEcriture = null;
}
/**
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
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
*/
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);