I have the following function. I want the loop to continue until the message equals "You have successfully logged in!". But when the user enters a wrong input (invalid username or password) then the loop goes on infinitely, because of an EOFException
. How can I solve this?
Thank you.
private void processConnection() throws IOException
{
boolean eofReached = false;
String message;
do
{
try
{
message = (String)input.readObject();
if(message.equals("You have successfully logged in!"))
{
displayMessage(String.format("\n%s ", message));
logged = true;
prepareUI();
}
else
{
displayMessage(String.format("\n%s %s", message, "\nTry again!") );
}
}
catch (ClassNotFoundException | EOFException ex)
{
System.out.printf("\nend of registering");
// Logger.getLogger(ClientJFrame.class.getName()).log(Level.SEVERE, null, ex);
//eofReached = true;
}
cout("registering");
} while(!logged && !eofReached);
}