import java.io.IOException; import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; import java.util.Scanner; public class Client { private Socket socket; private Scanner scanner; private Client(InetAddress serverAddress, int serverPort) throws Exception { this.socket = new Socket(serverAddress, serverPort); this.scanner = new Scanner(System.in); } private void start() throws IOException { String input; System.out.println("Provide me with the herbs I need to make you a “special” potionPress 1 to continue"); PrintWriter out = new PrintWriter(this.socket.getOutputStream(), true); if (0 == scanner.nextLine().compareTo("1")) { out.println("make-potion"); out.flush(); } else { System.out.println("Come back when you have the herbs"); } System.out.println("Excellent! Here is your reward! Press 1 to continue"); if (0 == scanner.nextLine().compareTo("1")) { out.println("receive-potion"); out.flush(); } start(); } public static void main(String[] args) throws Exception { Client client = new Client( InetAddress.getByName(args[0]), Integer.parseInt(args[1])); System.out.println("\r\nConnected to Server: " + client.socket.getInetAddress()); client.start(); } }