If I end the client session a EOFException is thrown but I read that this would be normal so I just start a new thread with the same functionality but the value of Restaurant=null; although i wrote it in a .txt file
public void run(){
try {
ois= new ObjectInputStream(clientside.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
oos = new ObjectOutputStream(clientside.getOutputStream());
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
handlerequest(ois,oos);// exit();
}
I dont think that you need the code of my request handler so I wont attach it to reduce code spamming. The method which invokes the following is the requesthandler
String tempRestaurant=null;
try {
fr = new FileReader("Restaurant.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fr.read(cbuf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tempRestaurant=String.valueOf(cbuf);
System.out.println(tempRestaurant);
try {
oos.writeObject(tempRestaurant);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I´m looking foward to your help pls write if you need more information code etc. :) This is the Exception below which is thrown after exiting the client
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at prealphaserverpackage.clientsidethreads.setRestaurant(Serverpart.java:164)
at prealphaserverpackage.clientsidethreads.handlerequest(Serverpart.java:205)
at prealphaserverpackage.clientsidethreads.run(Serverpart.java:96)
Exception in thread "Thread-3" java.lang.NullPointerException
at java.io.PrintWriter.write(Unknown Source)
at prealphaserverpackage.clientsidethreads.setRestaurant(Serverpart.java:177)
at prealphaserverpackage.clientsidethreads.handlerequest(Serverpart.java:205)
at prealphaserverpackage.clientsidethreads.run(Serverpart.java:96)
i added know your code to mine but still is the restaurant null after EOFException has been thrown...
Fixed it
i forgot to add the break line in the switch case szenario in my request handler sry it was my fault... thx for helping me to avoid the EOFException :)