# Failed on step "Respond to multiple PINGs #wy1"

**URL:** <https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [April 2, 2025, 9:28pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116 "2025-04-02T21:28:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![artm1904](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/artm1904/32/8484_2.png) [@artm1904](https://forum.codecrafters.io/u/artm1904)\
**Post date:** [April 2, 2025, 9:28pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/1 "2025-04-02T21:28:28Z")

</div>

I wrote my own c++ imp, but it doesn’t work properly.  
Then i copied one of the solutions from “Code examples”, but is doesn’t work too.  
Can anyone help me? I really stuck on it (

Here is my code impl:

```auto
#include <arpa/inet.h> //function for translating IP address from string to binary format
#include <netdb.h> //to get information about host (gethostbyname)
#include <sys/socket.h> //declare data for socket
#include <sys/types.h> //declare types of system data calls
#include <unistd.h> //to system functions, close file descript (handle)

#include <cstdlib> //lib for common functions, e.g EXIT
#include <cstring> //to work with string in C-style, strcpy
#include <iostream> //lib for input streams output streams
#include <string>

int main(int argc, char **argv) {
  // Flush after every std::cout / std::cerr
  std::cout << std::unitbuf;
  std::cerr << std::unitbuf;

  // Create new socket, AF_INET - use IPV4 address, SOCK_STREAM - use TCP
  // socket, 0 - default val for TCP socket
  int server_fd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_fd < 0) {
    std::cerr << "Failed to create server socket\n";
    return 1;
  }

  // Since the tester restarts your program quite often, setting SO_REUSEADDR
  // ensures that we don't run into 'Address already in use' errors
  int reuse = 1;
  if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
    std::cerr << "setsockopt failed\n";
    return 1;
  }

  struct sockaddr_in server_addr;
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = INADDR_ANY;
  server_addr.sin_port = htons(6379);

  if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) != 0) {
    std::cerr << "Failed to bind to port 6379\n";
    return 1;
  }

  int connection_backlog = 5;
  if (listen(server_fd, connection_backlog) != 0) {
    std::cerr << "listen failed\n";
    return 1;
  }

  struct sockaddr_in client_addr;
  int client_addr_len = sizeof(client_addr);
  std::cout << "Waiting for a client to connect...\n";

  std::cout << "Logs from your program will appear here!\n";
  int client_fd;

  client_fd = accept(server_fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);

  if (client_fd < 0) {
    std::cerr << "Failed to accept connection\n";
    return 1;
  }

  std::cout << "Client connected\n";

  // Simulate handling client requests and responding to commands
  char buff[128] = "";
  bzero(&buff, sizeof(buff));
  while (1) {
    memset(&buff, '\0', sizeof(buff));
    recv(client_fd, buff, 15, 0);
    if (strcasecmp(buff, "*1\r\n$4\r\nping\r\n") != 0) {
      bzero(&buff, sizeof(buff));
      continue;
    }
    send(client_fd, "+PONG\r\n", 7, 0);
  }

  close(server_fd);

  return 0;
}

```

Here is the git push remote logs:

```auto
artm1904@DESKTOP-CIVJLLL:~/c++_projects/codecrafters-redis-cpp$ git push origin master
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 185 bytes | 185.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: ------------------------------------------------------------------------
remote: 
remote: 
remote: _______ __ _                   
remote: / __\___  __| |___ / __\___  ___ / _|| |____ _ _____ 
remote: / / / _ \ / _` | / _ \ / / | ' __|/ _` || |_ |__ |/ _ \| ' __|/__ |
remote: / /___| (_) || (_| ||__// /___| | | (_| || _|| |_|__/| | \__ 
remote: \ ____/ \___ / \ __,_| \___ |\ ____/|_| \__ ,_||_| \ __|\___ ||_| |___/
remote: 
remote: 
remote: Welcome to CodeCrafters! Your commit was received successfully.
remote: 
remote: ------------------------------------------------------------------------
remote: 
remote: ⏳ Turbo test runners busy. You are in queue.
remote: 

remote: 
remote: Running tests on your code. Logs should appear shortly...
remote: 
remote: [compile] -- Running vcpkg install
remote: [compile] Detecting compiler hash for triplet x64-linux...
remote: [compile] Compiler found: /usr/local/bin/c++
remote: [compile] All requested packages are currently installed.
remote: [compile] Total install time: 89.2 us
remote: [compile] -- Running vcpkg install - done
remote: [compile] -- The C compiler identification is GNU 13.2.0
remote: [compile] -- The CXX compiler identification is GNU 13.2.0
remote: [compile] -- Detecting C compiler ABI info
remote: [compile] -- Detecting C compiler ABI info - done
remote: [compile] -- Check for working C compiler: /usr/bin/cc - skipped
remote: [compile] -- Detecting C compile features
remote: [compile] -- Detecting C compile features - done
remote: [compile] -- Detecting CXX compiler ABI info
remote: [compile] -- Detecting CXX compiler ABI info - done
remote: [compile] -- Check for working CXX compiler: /usr/local/bin/c++ - skipped
remote: [compile] -- Detecting CXX compile features
remote: [compile] -- Detecting CXX compile features - done
remote: [compile] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
remote: [compile] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
remote: [compile] -- Found Threads: TRUE
remote: [compile] -- Configuring done (1.7s)
remote: [compile] -- Generating done (0.0s)
remote: [compile] -- Build files have been written to: /app/build
remote: [compile] [50%] Building CXX object CMakeFiles/server.dir/src/Server.cpp.o
remote: [compile] [100%] Linking CXX executable server
remote: [compile] [100%] Built target server
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.
remote: 
remote: [tester::#WY1] Running tests for Stage #WY1 (Respond to multiple PINGs)
remote: [tester::#WY1] $ ./your_program.sh
remote: [your_program] Waiting for a client to connect...
remote: [your_program] Logs from your program will appear here!
remote: [your_program] Client connected
remote: [tester::#WY1] client-1: $ redis-cli PING
remote: [tester::#WY1] Received "PONG"
remote: [tester::#WY1] client-1: > PING
remote: [tester::#WY1] write tcp 127.0.0.1:50332->127.0.0.1:6379: write: broken pipe
remote: [tester::#WY1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
remote: 

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 3, 2025, 7:42pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/3 "2025-04-03T19:42:59Z")

</div>

Hey @artm1904, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![artm1904](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/artm1904/32/8484_2.png) [@artm1904](https://forum.codecrafters.io/u/artm1904)\
**Post date:** [April 3, 2025, 8:05pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/5 "2025-04-03T20:05:01Z")

</div>

Hello, this git-repo contains solutions. I tried to pass the test with this solution and it failed

> **[GitHub - artm1904/Redis-C-: Build your own Redis impl](https://github.com/artm1904/Redis-C-)**
>
> Build your own Redis impl

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 3, 2025, 8:11pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/6 "2025-04-03T20:11:32Z")

</div>

Looks like you’ve made it past this stage. Great job!

Let me know if you still need any help with it.

---

<div class="post-metadata">

**Author:** ![artm1904](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/artm1904/32/8484_2.png) [@artm1904](https://forum.codecrafters.io/u/artm1904)\
**Post date:** [April 3, 2025, 8:16pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/7 "2025-04-03T20:16:46Z")

</div>

Sorry… i found my fool mistake  
I do changes in my code and the always use below commands:

1. git commit --allow-empty -m “[any message]”
2. git push origin master

I do not really push my changes to remote server)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 8, 2025, 8:17pm UTC](https://forum.codecrafters.io/t/failed-on-step-respond-to-multiple-pings-wy1/8116/8 "2025-04-08T20:17:26Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
