mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"fmt"
|
|
"gf/g/net/gtcp"
|
|
"io"
|
|
"log"
|
|
"time"
|
|
"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 {
|
|
|
|
}
|
|
} |