/** * main.cpp is the manager. It hires a NetworkStarter, checks if it was told to be a "server" or a "client", * creates that object, and tells it to do its job. It doesn't need to know the messy details of sockets */ #include "NetworkConfig.h" #include "EchoServer.h" #include "SimpleClient.h" #include #include int main(const int argc, char* argv[]) { // 1. Turn on the networking rulebook NetworkStarter network; // 2. Check what the user typed when they ran the program if (argc > 1 && std::string(argv[1]) == "server") { EchoServer server(8080); server.start(); // Boss says: "Server, start working!" } else if (argc > 1 && std::string(argv[1]) == "client") { if (SimpleClient client; client.connectTo("127.0.0.1", 8080)) { client.talk("Hello, Server! Are you there?\n"); client.talk("This is a second message!\n"); } } else { std::cout << "How to use:\n"; std::cout << " Run as Server: echo_app server\n"; std::cout << " Run as Client: echo_app client\n"; } return 0; }