Ihsan Junaidi Ibrahim
unread,Nov 12, 2013, 10:07:17 AM11/12/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hi,
I'm trying to implement a UDP ping mechanism but my code currently returns io.timeout.
Since no packets ever reach the UDP port except for ICMP replies, hence net.Error returned io.timeout
Is there a way I can obtain the reply or at least test for a different error condition that reflect unreachable errors?
--
var con *net.UDPConn
if con, err = net.ListenUDP(udp, laddr); err != nil {
return rtt, tgt, err.(net.Error)
}
defer con.Close()
con.SetDeadline(t.Add(100 * time.Millisecond))
if _, err = con.WriteToUDP([]byte("PING"), addr); err != nil {
return rtt, tgt, err.(net.Error)
}
var buf = make([]byte, 4)
if _, _, err = con.ReadFromUDP(buf); err != nil {
return rtt, tgt, err.(net.Error)
}