public static void main(String[] args) throws IOException {
		String keyFileName;
		try {
			keyFileName = args[args.length-1];
			if(keyFileName.startsWith("-"))
				throw new RuntimeException();
		} catch(RuntimeException e) {
			System.err.println("No key file specified.");
			return;
		}

		String addr = null;
		short port = 0;
		for(String s: args) {
			if(s.startsWith("--host")) {
				try {
					String[] spl = s.split(":");
					addr = spl[1];
					port = Short.parseShort(spl[2]);
				} catch(ArrayIndexOutOfBoundsException | NumberFormatException e) {
					System.err.println("Bad host format (example: --host:localhost:19090).");
					return;
				}
			}
		}
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		if(addr != null && port > 0) {
			try(Socket s = new Socket(addr, port)) {
				BufferedReader sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
				PrintWriter sout = new PrintWriter(s.getOutputStream());
				produceAnswer(sin, sout, keyFileName);
				(new RecvThread(sin, out)).start();
				
				while(true) {
					String l = in.readLine();
					if(l == null)
						break;
					sout.println(l);
					sout.flush();
				}
			}
		} else {
			produceAnswer(in, out, keyFileName);
		}

	}