aa
This commit is contained in:
21
main.go
21
main.go
@@ -1,8 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
@@ -163,8 +165,25 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleConn(c net.Conn) {
|
func handleConn(c net.Conn) {
|
||||||
|
if c == nil {
|
||||||
|
fmt.Println("conn is nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
reader := bufio.NewReader(c)
|
||||||
for {
|
for {
|
||||||
globals.SugarLogger.Debugf("tcp socket read:", utils.Format4Output(c, true))
|
//ReadString阻塞,直到读到\n
|
||||||
|
msg, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
fmt.Println("connection close")
|
||||||
|
} else {
|
||||||
|
fmt.Println("ReadString err", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("read data:", msg)
|
||||||
|
b := []byte("ok")
|
||||||
|
c.Write(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user