func handleRead(conn net.Conn, done chan string) { for { buf := make([]byte, 1024) reqLen, err := conn.Read(buf) if err != nil { fmt.Println("Error to read message", err.Error()) return } fmt.Println(string(buf[:reqLen - 1])) // 转化为16进制 buffer := new(bytes.Buffer) for _, b := range buf[:reqLen] { s := strconv.FormatInt(int64(b&0xff), 16) if len(s) == 1 { buffer.WriteString("0") } buffer.WriteString(s) } // 转化为字符串 fmt.Println(buffer.String()) } //done <- "read" }