tcp太痛苦了 功能好多流程还都杂糅在一起

This commit is contained in:
impact-eintr
2022-12-09 18:57:51 +08:00
parent e287d86855
commit 5324cb00cd
6 changed files with 31 additions and 29 deletions

View File

@@ -4,28 +4,17 @@ import (
"fmt"
"log"
"net"
"time"
)
func main() {
go func() {
conn, err := net.Dial("tcp", "192.168.1.1:9999")
if err != nil {
fmt.Println("err : ", err)
return
}
log.Println("连接建立")
conn.Write([]byte("helloworld"))
log.Println("发送了数据")
//buf := make([]byte, 1024)
//conn.Read(buf)
conn.Close()
}()
t := time.NewTimer(1000 * time.Millisecond)
select {
case <-t.C:
conn, err := net.Dial("tcp", "192.168.1.1:9999")
if err != nil {
fmt.Println("err : ", err)
return
}
//buf := make([]byte, 1024)
//conn.Read(buf)
if err = conn.Close(); err != nil {
log.Fatal(err)
}
}