mirror of
https://gitee.com/johng/gf.git
synced 2024-12-04 21:28:22 +08:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"fmt"
|
|
"gitee.com/johng/gf/g/net/gtcp"
|
|
"io"
|
|
"log"
|
|
"time"
|
|
"gitee.com/johng/gf/g/util/gutil"
|
|
)
|
|
|
|
func main() {
|
|
gtcp.NewServer(":8999", func(conn net.Conn) {
|
|
|
|
|
|
try := 0
|
|
buffersize := 5
|
|
data := make([]byte, 0)
|
|
for {
|
|
buffer := make([]byte, buffersize)
|
|
length, err := conn.Read(buffer)
|
|
if err != nil {
|
|
log.Println(err)
|
|
if err != io.EOF {
|
|
log.Println("node recieve:", err, "try:", try)
|
|
}
|
|
if try > 2 {
|
|
break;
|
|
}
|
|
try ++
|
|
time.Sleep(100 * time.Millisecond)
|
|
} else {
|
|
if length == buffersize {
|
|
data = gutil.MergeSlice(data, buffer)
|
|
} else {
|
|
data = gutil.MergeSlice(data, buffer[0:length])
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
fmt.Println(string(data))
|
|
}).Run()
|
|
select {
|
|
|
|
}
|
|
} |