views:

29

answers:

1

Hi I have a client and server program, all the coding is done and compiles, the client has a GUI and the server is command line. The program uses sockets.

But when I run the client to connect to the server it keeps coming with the error message: "Usage: TodoClient []", rather than connecting to the server and starting up.

This is where the problem lies:

 public static void main(String[] args) {

TodoClient client;



if (args.length > 2 || args.length == 0) {

  System.err.println("Usage: TodoClient <host> [<port>]");

} else if (args.length == 1) {

  client = new TodoClient(args[0], DEFAULT_PORT);

} else {

  client = new TodoClient(args[0], Integer.parseInt(args[1]));

}

}

Thank You

+1  A: 

You are running this with a host and optional port, aren't you ?

e.g.

java TodoClient localhost 8080
Brian Agnew
yes sort of, the port is 2288 on the server and the client is coded with this to connect to it, and i am trying to run it on the same machine so the server is localhost.this is the code for the cleint socket:this.socket = new Socket(remoteHost, port);
socket
There's nothing wrong with your code. The problem is elsewhere - the program is getting either 0 args or more than 2. It's most likely 0. What are you typing on the command line to start the client?
Skip Head
I am running both the server and client in Jcreater 4.0 and also tried in geany, havent used command line to run them. I'm thinking perhaps theres an issue with the host selection in some ways, i actually fully don't understand the args coding lol.Cheers
socket
The args array holds the command line arguments. You need to find the place in Jcreator where it let's you provide the arguments to the program when you run it.
Skip Head
I think ive managed to get it working, i set the "prompt for main method argument" option on and when running it in the rpompt typed the loopback address and the GUi loaded up.Thanks
socket