From a2cf7bc4c840d641f541387297440b70713870cf Mon Sep 17 00:00:00 2001 From: mochaoui Date: Thu, 18 Apr 2024 07:12:31 -0500 Subject: [PATCH] responding to Ping --- Server.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Server.cpp b/Server.cpp index 8066a14..e7fd98d 100644 --- a/Server.cpp +++ b/Server.cpp @@ -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::istringstream iss(command); iss >> cmd >> nick;