package test;import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;public class Server { private ServerSocket ss; public Server(int port) throws Exception {
this.ss = new ServerSocket(port);
} public void recive() {
InputStream is = null;
ObjectInputStream ios = null;
Socket clis;
try {
clis = ss.accept();
is = clis.getInputStream();
ios = new ObjectInputStream(is);
Object o = null; while ((o = ios.readObject()) != null) {
System.out.println(o);
}
ios.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public static void main(String[] args) throws Exception {
new Server(8888).recive();
}
}
package test;import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;public class Client { Socket client ;
public Client(String ip ,int port) throws Exception{
this.client = new Socket(ip ,port);
}

public void send () throws Exception {
OutputStream ops = null;
ObjectOutputStream oos = null;
ops = client.getOutputStream();
oos = new ObjectOutputStream(ops);
oos.writeObject(new String("djl"));
oos.writeObject(new String("ee"));

oos.close();
ops.close();
}

public static void main(String[] args) throws Exception {
new Client("127.0.0.1",8888).send();
}
}
出现的异常:
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2552)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at test.Server.recive(Server.java:26)
at test.Server.main(Server.java:45)出现出界异常,请问怎么避免啊?怎么样才可以连续读对象不出界啊??