ReuseUDPPort creates a new UDP connection on the same local address
(localAddr *net.UDPAddr)
| 58 | |
| 59 | // ReuseUDPPort creates a new UDP connection on the same local address |
| 60 | func ReuseUDPPort(localAddr *net.UDPAddr) (*net.UDPConn, error) { |
| 61 | conn, err := net.ListenUDP("udp", localAddr) |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("failed to reuse UDP port %d: %w", localAddr.Port, err) |
| 64 | } |
| 65 | return conn, nil |
| 66 | } |
| 67 | |
| 68 | // CloseUDPSocketGracefully closes a UDP socket with a small delay to ensure port release |
| 69 | func CloseUDPSocketGracefully(conn *net.UDPConn) { |