1

就像标题说的那样,在我在客户端调用 shutdownOutput() 之后,我在服务器端收到了 EOFException

这是在服务器端:

    public void getRestaurant() {     
String tempRestaurant=null;
try { BufferedReader fr =
           new BufferedReader( new FileReader( "Restaurant.txt" ));
      tempRestaurant = fr.readLine();
      System.out.println( tempRestaurant );
      System.out.println("writing tempRestaurant is the next Step");
    oos.writeObject(tempRestaurant);
    System.out.println("tempRestaurant has been written");
    oos.close();
    fr.close();
} catch (IOException ex) {
    ex.printStackTrace();
 }        
}

这是客户端的代码:

    protected String doInBackground(Void... params) {
    connecttoServer();
    System.out.println("connecting to server...");
    try {
        oos.writeInt(1);
        System.out.println("next step is closing");
        serverside.shutdownOutput();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {

        System.out.println("connected to server");
        Restaurant=(String) ois.readObject();
        System.out.println("doInBackground(): "+Restaurant);    

这是错误代码:

    java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readInt(Unknown Source)
at java.io.ObjectInputStream.readInt(Unknown Source)
at prealphaserverpackage.clientsidethreads.handlerequest(Serverpart.java:355)
at prealphaserverpackage.clientsidethreads.run(Serverpart.java:156)

如果您需要任何进一步的信息,请发表评论,我会尽快将它们放到网上 :)

4

1 回答 1

0

我忘了打电话oos.flush();当服务器还在等待数据时,我关闭了流。这就是EOFException.

于 2013-12-08T12:42:31.090 回答