Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support udp reconnection #263

Open
guidao opened this issue Sep 29, 2022 · 1 comment · May be fixed by #264 or #280
Open

Support udp reconnection #263

guidao opened this issue Sep 29, 2022 · 1 comment · May be fixed by #264 or #280

Comments

@guidao
Copy link

guidao commented Sep 29, 2022

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

@bessb bessb linked a pull request Oct 5, 2022 that will close this issue
@blakearnold
Copy link

Hi,
I opened #280 which should resolve this. Let me know if we can merge.

@blakearnold blakearnold linked a pull request Nov 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants