EOFException after calling socket.shutdownOutput()

123 views Asked by At

like the headline says I´m getting an EOFException on the serverside after i called shutdownOutput() at the clientside

this is at the serverside:

    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();
 }        
}

and this is the code at the clientside:

    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);    

and this is the error code:

    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)

pls comment if you need any further informations i will put them online as soon as possible :)

1

There are 1 answers

0
Sebastian Walla On BEST ANSWER

I forgot to call oos.flush(); While the server was still waiting for the data, I closed the stream. That was the reason for the EOFException.