开发者

Args error in main method for client-server program

开发者 https://www.devze.com 2022-12-29 23:40 出处:网络
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.

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 se开发者_如何学JAVArver 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


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

e.g.

java TodoClient localhost 8080
0

精彩评论

暂无评论...
验证码 换一张
取 消