Last active
September 29, 2020 11:09
-
-
Save marten-seemann/f376b2e89261b0dd2bd34e3f20002608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
) | |
func main() { | |
log.Fatal(run()) | |
} | |
const numWorkers = 10 | |
func run() error { | |
addr, err := net.ResolveUDPAddr("udp", "localhost:0") | |
if err != nil { | |
return err | |
} | |
ln, err := net.ListenUDP("udp", addr) | |
if err != nil { | |
return err | |
} | |
fmt.Println("Listening on:", ln.LocalAddr()) | |
raddr, err := net.ResolveUDPAddr("udp", "localhost:12345") | |
if err != nil { | |
return err | |
} | |
for i := 0; i < numWorkers; i++ { | |
go flood(ln, raddr) | |
} | |
select {} | |
} | |
func flood(conn *net.UDPConn, raddr *net.UDPAddr) { | |
b := []byte("foobar") | |
for { | |
if _, err := conn.WriteTo(b, raddr); err != nil { | |
panic(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment