Home > other >  You can't get a package golang udp even
You can't get a package golang udp even

Time:09-29


The code below

Package the main

Import (
"FMT"
".net "
"Time"
)
Var sendData publishes the event [6] byte=[6] byte {0 x01, 0 x0b, 0 XFF, 0 XFF, 0 x4a, 0 x9b}
Func test2 () {
IP:=net. ParseIP (" 192.168.8.33 ")
SrcAddr:=& amp; Net. UDPAddr {IP: net. IPv4zero, Port: 6001}
DstAddr:=& amp; Net. UDPAddr {IP, IP, Port: 6000}
Conn, err:=net. DialUDP (" udp, "srcAddr, dstAddr)
if err ! Nil={
FMT. Println (err)
}
Defer conn. Close ()
Go func () {
Data:=make (byte [], 1024)
For {
N, remoteAddr, err:=conn. ReadFromUDP (data)
if err ! Nil={
FMT. Printf (" error during the read: % s ", err)
}
FMT. Printf (" & lt; % s> The % s \ n ", remoteAddr, data [: n])
}
} ()
Conn. Write (sendData publishes the event [:])
B:=make (byte [], 1)
OS. Stdin. Read (b)
}

Wireshark caught, found that the udp send success, receive data, but ReadFromUDP has been suspended, what reason be
  • Related