客户端-服务器程序的主方法中的参数错误
您好,我有一个客户端和服务器程序,所有编码均已完成并编译,客户端有 GUI,服务器是命令行。该程序使用套接字。
但是当我运行客户端连接到服务器时,它不断出现错误消息:“Usage:TodoClient []”,而不是连接到服务器并启动。
这就是问题所在:
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]));
}
}
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用主机和可选端口运行它,不是吗?
例如
You are running this with a host and optional port, aren't you ?
e.g.