hello all. I’m stuck on Stage #QQ0. my code has passed course test. But when i run my code locally, i encounter some error:
i want to read bytes from client, but some data missed.
i used nc
to send data to my 0.0.0.0:6379:
echo -n "*2\r\n$4\r\nECHO\r\n$9\r\nraspberry\r\n" | nc 0.0.0.0 6379
but my server get data: "*2\r\n\r\nECHO\r\n\r\nraspberry\r\n"
. $4 and $9 have missed. Does anyone know what’s going on? thanks
this my code on github: codecrafters-redis-go/app/server.go at master · batreeon/codecrafters-redis-go · GitHub
func main() {
// You can use print statements as follows for debugging, they'll be visible when running tests.
fmt.Println("Logs from your program will appear here!")
l, err := net.Listen("tcp", "0.0.0.0:6379")
if err != nil {
fmt.Println("Failed to bind to port 6379")
}
defer l.Close()
for { // handle multiple client connections
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting connection: ", err.Error())
os.Exit(1)
}
go func() {
defer conn.Close()
for { // handle multiple commands in the same connection
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
fmt.Println("Error read request: ", err.Error())
return // return when one connection handler completed
}
fmt.Println("1 ", string(buf))
......
}
}()
}
}