回答に続いて: IntelliJ で単純なクライアント サーバー アプリケーションを作成している場合、これはどのように機能しますか? スレッドを続行するのに十分な評判がないためです。
main() メソッドを含むクラスを右クリックして [実行] を選択すると、パブリック クラスが IntelliJ の実行構成 (IntelliJ のボタン バーの緑色の矢印の左側にあるドロップダウン リスト) に追加され、[編集] を選択できます。このドロップダウンから「Configurations」をクリックして、コマンド ライン引数を変更します。「クライアント」または「サーバー」を引数として指定することで、クライアントまたはサーバーのいずれかを実行できます。同じプロジェクトからサーバーとクライアント クラスを実行するにはどうすればよいですか? 各クラスに 1 つずつ、2 つの main() メソッドが必要ですか?
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
}