我想用套接字发送一些Object,但这并不总是有效。有时它有效,有时不行。然后我得到一个StreamCorruptedException。我为什么要这个?我的客户在这里:
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
os.writeUTF(output);
os.flush();
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Post[] returnArray;
while ((returnArray = (Post[]) in.readObject()) != null) {
return returnArray;
}
我在这里收到错误:ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
在服务器上我有这个:
public void returnObjectPosts(Post[] sendPosts){
try{
ObjectOutputStream os = new ObjectOutputStream(client.getOutputStream());
os.writeObject(sendPosts);
os.flush();
os.close();
}catch(UnknownHostException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}