bufio.NewReader
通过 ReadLine读取每一行
func (t *TcpSocketUtil) syncreciveline() (string, error) { buf := bufio.NewReader(net.conn) for { data, _, eof := buf.ReadLine() if eof == io.EOF { break } else if eof != nil { fmt.Println(eof) return "", eof } fmt.Println(string(data)) } return "", nil }
通过 ReadBytes或者ReadSlice读取每一行
func (t *TcpSocketUtil) syncreciveline() (string, error) { buf := bufio.NewReader(net.conn) for { data, _, eof := buf.ReadBytes(' ') if eof == io.EOF { break } else if eof != nil { fmt.Println(eof) return "", eof } fmt.Println(string(data)) } return "", nil }