java.io.StreamCorruptedException: invalid type code: AC
问题描述:
private Server_Student Loginresult(String numberString ,String passworString) {
// TODO Auto-generated method stub
if (!isConnected) {
for (int i = 0; i < 10; i++) {
getsocket();
}
}
Student student = new Student(numberString, passworString);
Client_Student client_Student = new Client_Student(student);
Server_Student server_Student = null;
try {
oos.writeObject(client_Student);
server_Student = (Server_Student) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Loginresult出错了");
}
System.out.println(server_Student);
return server_Student;
}
server_Student = (Server_Student) ois.readObject(); 这里一直出现错误,但是不明白哪里错了.求解
答
强转的类型是不是搞错了?
你先不强转看报不报错。
答
感谢感谢 !找到错误的地方了.
ois是有值的,就是调用readobject()方发是空的,
后来发现在服务器端应该用ObjectOutputsream oos写的时候用已有的socket创建了一个
ObjectOutputsream objectoutputsream;
应该错误就在这里,因为有看到其他博客有说到一个socket不能有两个ObjectOutputsream对象