gf/.example/net/gtcp/gtcp_echo_server.go

25 lines
370 B
Go
Raw Normal View History

2018-07-20 11:41:23 +08:00
package main
import (
2019-04-03 00:03:46 +08:00
"fmt"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/net/gtcp"
2018-07-20 11:41:23 +08:00
)
func main() {
2019-04-03 00:03:46 +08:00
gtcp.NewServer("127.0.0.1:8999", func(conn *gtcp.Conn) {
defer conn.Close()
for {
data, err := conn.Recv(-1)
if len(data) > 0 {
if err := conn.Send(append([]byte("> "), data...)); err != nil {
fmt.Println(err)
}
}
if err != nil {
break
}
}
}).Run()
}