1
我正在构建客户端 - 服务器应用程序。现在我想用此代码将消息从客户端转发到所有其他客户端:Java无效流标头:7371007E
ArrayList<User> usrs = _usrHandler.getUsers();
for(User usr : usrs) {
if(!usr.getSocket().equals(_connection)) {
usr._oOut.writeObject(new CommunicationMessage(this._comMsg.getMessage(), CommunicationMessage.MSG,
this._comMsg.getUser()));
}
}
在客户端,程序正在侦听消息。它引发此异常:
java.io.StreamCorruptedException: invalid stream header: 7371007E
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at Connection$MessageListener.run(Connection.java:126)
at java.lang.Thread.run(Thread.java:637)
消息监听:
while(this._loop) {
this._comMsg = (CommunicationMessage) this._dataInput.readObject();
SimpleAttributeSet attr = new SimpleAttributeSet();
attr.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
attr.addAttribute(StyleConstants.CharacterConstants.Foreground, _comMsg.getUser().getColor());
messageClient.addMessage(_comMsg.getUser().getNickName() + ": ", attr);
messageClient.addMessage(_comMsg.getMessage(), _comMsg.getUser().getColor());
_comMsg = null;
}
是否有人看到错误?
我现在看到我的错误。我改变了构造侦听器线程的方式,但没有意识到'InputStream'仍然是在run()方法中构建的。谢谢! – dododedodonl 2010-01-31 13:14:12