public static void main(String[] args) {

		if(args.length == 0)
			port = Integer.valueOf(64501);
		else
			port = Integer.valueOf(args[1]);

		try (ServerSocket serverSocket = new ServerSocket(port)){

			System.out.println("Server is waiting for an incoming connection on host="
					+ InetAddress.getLocalHost()
					+ " port=" + serverSocket.getLocalPort());


			try(Socket socket = serverSocket.accept();
					BufferedReader serverInput = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					PrintStream	serverOutput = new PrintStream(socket.getOutputStream())){

				dictionary = new CapitalsDictionary("capitals.txt");

				String[] cntrCptlPair = dictionary.getRandomPair();

				String askedCountry,askedCapital,answeredCapital;

				while(true){
					cntrCptlPair = dictionary.getRandomPair();

					askedCountry=cntrCptlPair[1];
					askedCapital=cntrCptlPair[0];
					System.out.println("askedCountry" + askedCountry);
					System.out.println("askedCapital" + askedCapital);

					//						if(serverInput != null && serverInput.)
					askClient(serverOutput,askedCountry);

					answeredCapital = getAnswer(serverInput);
					if(answeredCapital == null){
						
						System.out.println("Something totally went wrong, answer is null. Maybe client stopped unexpectedly.");
						System.exit(1);
					}

					System.out.println("answeredCapital" + answeredCapital);

					if(answeredCapital.equals("q") || answeredCapital.equals("quit") || answeredCapital.equals("error"))
						break;

					sendCorrectnessToClient(serverOutput, isCorrectAnswer(answeredCapital, askedCountry), askedCapital);
				}



				System.out.println("server is shutting down.");
			}

		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Fuck you, I'm not gonna work.");
		}catch(Exception e){
			System.out.println("server is shutting down unexpectedly");
		}

	}