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 に答える