package test;
import java.util.*;
import sun.security.krb5.internal.UDPClient;
import java.net.*;
public class CMD {
public static void main(String[] args) throws UnknownHostException, SocketException {
DatagramSocket sock = new DatagramSocket ();
Scanner keyboard = new Scanner(System.in);
String fisrtarg=null;
// System.out.println("Enter CMD");
// fisrtarg = keyboard.nextLine();
if (args.length > 0) {//this is important if no arguments where given a small help or information should pop up
for (int i = 0; i < args.length; i++) {
System.out.println("Argument: " + i + " " + args[i]);
if (i == 0) {
fisrtarg = args[i];
}
else if (args.length != 4 ){
System.out.println("must Input 4 args : EXIT!");
System.exit(0);
}
}
} else {//help should pop up here this menas no arguments were given
System.out.println("No arguments given!");
System.out.println("use -e to exit");
System.out.println("-t : UDP or TCP");
System.out.println("-x : the integer that will send");
System.out.println("-s : host name of the server ");
System.out.println("-p : the port being used by the server ");
System.exit(0);
}
if(fisrtarg.equals("-x")){
}
if(fisrtarg.equals("-t")){
}
if(fisrtarg.equals("-p")){
try{
int servPort = 0;
String servName = null;
servPort=keyboard.nextInt();
if(servPort > 10000 && servPort < 65536){
UDPCliet udp = new UDPCliet(sock,servName,servPort);
}
else{
System.out.println("Port Number Must Be Between 10001 to 65535");
}
}catch(NumberFormatException e){
System.out.println("Port must be only Integer");
}
if(fisrtarg.equals("s")){
}
if (fisrtarg.equals("-e")) {
System.out.println("Requested to exit by using -e");
System.exit(0);
} else {
System.out.println("No such argument!");
System.out.println("use -e to exit program with no output at all except the argument given");
System.exit(0);
}
}
}
}
Agin sorry for so many question in these day
I wanna know i'm getting into the right take for the command line arg ?