Package main

Source Code of main.Main

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import model.Context;

/**
*
* @author Shadowbring
*/
public class Main implements Serializable {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     * @throws java.lang.ClassNotFoundException
     */
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
        Socket socket = new Socket("localhost", 24891);
        if (socket.isConnected()) {
            System.out.println("Connection to Quiz Server has been established! Waiting for questions...");
        } else {
            System.out.println("Quiz Server is currently unavailable. Try again later.");
            System.exit(0);
        }
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        while (true) {
            Context context = (Context) ois.readObject();
            System.out.println(context.getQuestion());
            for (String variant : context.getVariants()) {
                System.out.println(variant);
            }
            context.setVariant(Integer.parseInt(keyboard.readLine()));
            oos.writeObject(context);
            oos.flush();
            context = (Context) ois.readObject();
            System.out.println(context.getResult());
        }
    }

}
TOP

Related Classes of main.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.