import java.io.*;
import java.net.*;
import java.lang.*;

public class echoUDPClient {
    private static String host = "localhost"; //Default Echo server
    private static int port = 7; //Default echo port
    private static InetAddress serveraddr;


    private static boolean ParseInput(String[] line) {

        String arg;

        for (int i = 0; i < line.length; i++) {

            arg = line[i];

            if (arg.equals("-h")) {

                host = line[++i];

            } else if (arg.equals("-p")) {

                port = Integer.parseInt(line[++i]);

            } else {

                System.out.println("Usage error: Incorrect parameter(s)");

                PrintUsage();

                return false;

            }


        }
        // host argument validation
        try {
            serveraddr = InetAddress.getByName(host);
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return false;
        }

        // Port is out or range
        return ((port > 0) && (port <= 65535));

    }

    private static void PrintUsage() {
        final String usage = "java echoUDPClient [-h host] [-p port]"
                + "\n\nDESCRIPTION: Echo UDP client"
                + "\n\nArguments:"
                + "\n\t-h host (optional): host is a domain name or IP of Echo server. Default value \"localhost\"."
                + "\n\t-p port (optional): port is the  UDP of Echo server. Default value 7.";
        System.out.println(usage);

    }

}
