我正在尝试ChatMassage
从流中读取一个对象并使用它的方法打印一条消息(该对象包含)getMassage()
。它第一次打印一条消息,但下一次它总是打印第一条消息。怎么了?
以下是代码示例:
while(keepGoing){
System.out.println("Client: " + ((ChatMassage) in.readObject()).getMassage() + "\n" );
}
聊天按摩类:
public class ChatMassage implements Serializable {
String msg, recipientName = null;
String senderName = "None";
public void setMassage(String msg) {
this.msg = msg;
}
public void setRecipientName(String recName) {
recipientName = recName;
}
public String getMassage() {
return msg;
}
public String getRecipientName() {
return recipientName;
}
public void setSenderName(String name) {
senderName = name;
}
public String getSenderName() {
return senderName;
}
}