证明socket是全双工,read,write是相互独立的

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 协议》,转载必须注明作者和本文链接
九九一十八,一步一个脚印
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!