package main
import (
"fmt"
"net"
"time"
)
func main() {
listener, _ := net.Listen("tcp","0.0.0.0:5566")
go func() {
client, _ := net.Dial("tcp", "127.0.0.1:5566")
s := "hello"
client.Write([]byte(s))
s2 := "world"
client.Write([]byte(s2))
}()
conn, _ := listener.Accept()
time.Sleep(time.Second * 10)
var buf [10]byte
conn.Read(buf[:]) // [104 101 108 108 111 119 111 114 108 100]
fmt.Println(buf)
conn.Read(buf[:])
fmt.Println(buf) // empty
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結