dosi8657
2014-08-24 06:44
浏览 72

进入bufio.Scanner在读取与Redis的TCP连接时停止

Reading TCP connection between Redis-server by using bufio.Scanner

fmt.Fprintf(conn, "*3
$3
SET
$5
mykey
$7
Hello!!
")
scanner := bufio.NewScanner(conn)
for {
    // fmt.Println("marker00")
    if ok := scanner.Scan(); !ok {
        // fmt.Println("marker01")
        break
    }
    // fmt.Println("marker02")
    fmt.Println(scanner.Text())
}

"+OK" comes as the result for first scanning, but the second scanning stops just in invoking Scan method. (marker00 -> marker02 -> marker00 and no output any more)

Why does Scan stop and how can I know the end of TCP response (without using bufio.Reader)?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题