This commit is contained in:
suyl
2021-06-24 09:41:01 +08:00
parent c246a94365
commit afea334ca0

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"bufio"
"flag" "flag"
"fmt" "fmt"
"io" "io"
@@ -172,10 +171,10 @@ func handleConn(c net.Conn) {
return return
} }
defer c.Close() defer c.Close()
reader := bufio.NewReader(c) //reader := bufio.NewReader(c)
buffer := make([]byte, 1024)
for { for {
//ReadString阻塞直到读到\n n, err := c.Read(buffer)
msg, err := reader.ReadString('\n')
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
fmt.Println("connection close") fmt.Println("connection close")
@@ -184,7 +183,7 @@ func handleConn(c net.Conn) {
} }
return return
} }
fmt.Println("read data", msg) fmt.Println("read data", buffer[:n])
b := []byte("ok") b := []byte("ok")
c.Write(b) c.Write(b)
} }