responding to Ping

This commit is contained in:
mochaoui
2024-04-18 07:12:31 -05:00
parent fb1fffabec
commit a2cf7bc4c8

View File

@@ -390,7 +390,20 @@ void Server::handleClientData(int fd) {
// } // }
// } // }
} }
if (startsWith(command, "nick")) { else if (startsWith(command, "PING"))
{
std::istringstream iss(command);
std::string serverHostname = command.substr(5); // Skip the "PING " prefix
// Construct the PONG message with the server hostname
std::string pongMessage = "PONG " + serverHostname + "\r\n";
// Send the PONG message back to the client
send(fd, pongMessage.c_str(), pongMessage.length(), 0);
std::cout << "ping was sent" << std::endl;
}
else if (startsWith(command, "nick")) {
std::string cmd, nick; std::string cmd, nick;
std::istringstream iss(command); std::istringstream iss(command);
iss >> cmd >> nick; iss >> cmd >> nick;