#include #include #include #include int main() { ListenSocket socket(12345); std::cout << "Listening on 12345" << std::endl; std::vector clients; ClientSocket *client; int loop = 0; while (socket.good()) { loop += 1; socket.wait_for_event(5000); client = socket.get_client(); if (client != 0) { clients.push_back(client); std::cout << "Client from " << client->get_addr() << std::endl; client->putline("Hello"); } unsigned int i; std::string line(""); for (i = 0; i < clients.size(); i++) { std::ostringstream message(""); message << "pong " << loop; clients.at(i)->putline(message.str()); if (clients.at(i)->getline(line)) { std::cout << "From " << i << ": " << line << std::endl; clients.at(i)->putline("Gotcha!"); } if (!clients.at(i)->good()) { std::cout << "Client " << i << " not good!" << std::endl; socket.release_client(clients.at(i)); clients.erase(clients.begin() + i); } } } std::cout << "End" << std::endl; }