* @throws java.io.IOException
* @throws java.lang.ClassNotFoundException
*/
public static void main(String[] args) throws IOException, ClassNotFoundException {
QuestionList questionList = new QuestionList();
Context context = null;
int attempt = 0;
int rightAnswers = 0;
String result;
ServerSocket server = new ServerSocket(24891);
System.out.println("Server Started");
Socket socket = server.accept();
System.out.println("New client on port" + socket.getPort());
ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
while (true) {
if (questionList.next() != null) {
context = readQuestion(questionList.next());
}
output.writeObject(context);
output.flush();
context = (Context) input.readObject();
attempt++;
if (questionList.isRight(context.getVariant())) {
result = "Congratulations! It is the right answer";
rightAnswers++;
} else {
result = "It is the wrong answer";
}
result = result.concat(attempt % 10 == 0 ? (" " + rightAnswers + "/" + attempt) : "");
context.setResult(result);
output.writeObject(context);
output.flush();
}
}