#include "NetworkConfig.h" #include "server/ServerSocketThread.h" #include "SimpleClient.h" #include #include #include #include int main(int argc, char* argv[]) { NetworkStarter network; if (argc > 1 && std::string(argv[1]) == "server") { ServerSocketThread server(8080); // 1. Start the server in the background server.start(); // 2. Simulate the server running for 10 seconds. // In a real app, this might be waiting for a user to press 'q' to quit. std::cout << "⏳ Server will run for 10 seconds, then auto-stop...\n"; std::this_thread::sleep_for(std::chrono::seconds(10)); // 3. Send the interrupt command! server.stop(); std::cout << "🏁 Main program is now exiting.\n"; } else if (argc > 1 && std::string(argv[1]) == "client") { SimpleClient client; if (client.connectTo("127.0.0.1", 8080)) { client.talk("Hello, Threaded Server!\n"); client.talk("Are you still listening?\n"); } } else { std::cout << "How to use:\n"; std::cout << " Run Server (runs for 10s then stops): echo_app server\n"; std::cout << " Run Client (connects to server): echo_app client\n"; } return 0; }