private List<PrintWriter> clients;
PrintWriter out = null;
try {
// out = new PrintWriter(new OutputStreamWriter(incoming.getOutputStream()));
oos = new ObjectOutputStream(incoming.getOutputStream());
// inform the server of this new client
// ChatServer.this.addClient(out);
// out.print("Welcome to AndyChat! ");
// out.println("Enter BYE to exit.");
// out.flush();
ois = new ObjectInputStream(incoming.getInputStream());
// BufferedReader in = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
for (;;) {
SendTalkData msg = (SendTalkData) ois.readObject();
if (msg == null) {
break;
} else {
// if (msg.trim().equals("BYE"))
// break;
System.out.println("Received: " + msg.toString());
// broadcast the receive message
ChatServer.this.broadcast(msg);
}
}
incoming.close();
ChatServer.this.removeClient(oos);
} catch (Exception e) {
if (oos != null) {
ChatServer.this.removeClient(oos);
}
e.printStackTrace();
}
/** Adds a new client identified by the given print writer. */
private void addClient(ObjectOutputStream oos) {
synchronized(clients) {
clients.add(oos);
}
}
현재 PrintWriter 객체를 client 로 하여 저장하여서, 서버에 붙은 모든 기기들에게 메세지를 브로드캐스트 하였지만 , ObjectOutputStream 으로 변경을 하여 저장을 하고 나니 저장이 되지 않아 broadcast 가 불가능 하게 되었습니다.
기기들의 값을 저장 할수 있는 클래스가 따로 더 있는지에 대해 여쭈어 보고 싶습니다.