Files
netstack/cmd/udp_client/main.go
impact-eintr be40f904fc udp通信的Connect 和 Read 结束 明天看Waiter 这相当于linux内核的事件驱动机制
当有某种事件就绪后通知waiter 监听着waiter的监听者就能通过waiter得知事件已经发生 从而不再阻塞
2022-12-01 22:36:40 +08:00

43 lines
765 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"flag"
"log"
"net"
)
func main() {
var (
addr = flag.String("a", "192.168.1.1:9999", "udp dst address")
)
log.SetFlags(log.Lshortfile | log.LstdFlags)
udpAddr, err := net.ResolveUDPAddr("udp", *addr)
if err != nil {
panic(err)
}
log.Println("解析地址")
// 建立UDP连接只是填息了目的IP和端口并未真正的建立连接
conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
panic(err)
}
log.Println("TEST")
send := []byte("hello")
if _, err := conn.Write(send); err != nil {
panic(err)
}
log.Printf("send: %s", string(send))
//recv := make([]byte, 10)
//rn, _, err := conn.ReadFrom(recv)
//if err != nil {
// panic(err)
//}
//log.Printf("recv: %s", string(recv[:rn]))
}