# Respond to Multiple Pings #wy1

**URL:** <https://forum.codecrafters.io/t/respond-to-multiple-pings-wy1/2568>\
**Category:** General\
**Tags:** challenge:redis\
**Created:** [October 25, 2024, 3:31am UTC](https://forum.codecrafters.io/t/respond-to-multiple-pings-wy1/2568 "2024-10-25T03:31:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shreyasganesh0](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/shreyasganesh0/32/2559_2.png) [@shreyasganesh0](https://forum.codecrafters.io/u/shreyasganesh0)\
**Post date:** [October 25, 2024, 3:31am UTC](https://forum.codecrafters.io/t/respond-to-multiple-pings-wy1/2568/1 "2024-10-25T03:31:58Z")

</div>

```auto
def main():
    # You can use print statements as follows for debugging, they'll be visible when running tests.
    print("Logs from your program will appear here!")

    server_socket = socket.create_server(("localhost", 6379), reuse_port=True)
    
    server_socket.listen(6379) # listen on the port

    while True:
        client_socket,address = server_socket.accept() # wait for client request and accept the connection
        
        while True:
            data_input = client_socket.recv(2048) # read the data from the client

            if not data_input:
                break

            client_socket.send(b"+PONG\r\n") # reply to the client with pong (hardcoded for now)
            
        if not data_input:
            break

    
    client_socket.close()

```

I submitted this code and it works but it looks like utter garbage and I know that im writing some redudant logic somewhere but im unable to figure out what it is because I dont know enough yet is this really the right way to read multiple messages from one client socket?

---

<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:** [October 25, 2024, 5:57am UTC](https://forum.codecrafters.io/t/respond-to-multiple-pings-wy1/2568/2 "2024-10-25T05:57:46Z")

</div>

@shreyasganesh0 The inner `while True` is absolutely correct as you need to read multiple commands from the same connection (socket).

However, the outer `while True` is probably unneccesary.

---

<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:** [October 30, 2024, 5:58am UTC](https://forum.codecrafters.io/t/respond-to-multiple-pings-wy1/2568/3 "2024-10-30T05:58:03Z")

</div>

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