intellij java execute client and server from same project
Following on from the answer to: If I am creating a simple client server
application in IntelliJ, how should this work? as I don't have enough
reputation to continue the thread.
When I right-click on the class containing the main() method and select
"run" the public class is added to IntelliJ's run configurations (the
dropdown list to the left of the green arrow on IntelliJ's button bar) and
I can choose "Edit Configurations" from this dropdown to change the
command line arguments. I can run either client or server by putting
"client" or "server" as the argument. How do I run the server and then the
client classes from the same project? Do I need two main() methods, one in
each class?
import java.io.IOException;
public class serversocket {
public static void main(String args[]) throws IOException {
System.out.println(args[0]); //debug
if (args[0] == "client") {
runClient();
} else if (args[0] == "server") {
runServer();
} else {
System.out.println("no arguments.");
}
}
private static void runClient() throws IOException {
System.out.println("Client running..."); //test
}
private static void runServer() throws IOException {
System.out.println("Server running..."); //test
}
No comments:
Post a Comment