Support udp reconnection
Opened this issue · 1 comments
guidao commented
For a "connected UDP socket", write will return an error when the udp port is unreachable, so it might be possible to perform a reconnection based on this error.
package main
import (
"fmt"
"net"
"time"
)
func main() {
conn, err := net.Dial("udp", "127.0.0.1:9999")
if err != nil {
panic(err)
}
for {
n, err := conn.Write([]byte("xxx.yyy.zzz.count:1|c"))
if err != nil {
fmt.Println("conn write failed:", err)
} else {
fmt.Println("conn write byte:", n)
}
time.Sleep(time.Second)
}
}
result:
conn write byte: 21
conn write failed: write udp 127.0.0.1:62924->127.0.0.1:9999: write: connection refused
conn write byte: 21
conn write failed: write udp 127.0.0.1:62924->127.0.0.1:9999: write: connection refused
conn write byte: 21
This feature is useful when the dns changes
blakearnold commented
Hi,
I opened #280 which should resolve this. Let me know if we can merge.