我有一个创建UDP服务器所需的端口列表。我试过这个 aproach
for _, r := range routingTable.Routes {
if r.Metric == 0 {
wg.Add(1)
go func() {
conn, err := net.ListenUDP("udp4", &r.OriginPort)
if err != nil {
log.Fatalf("Error occured starting the server: %s", err)
} else {
log.Printf("Listening on port: %s", r.OriginPort.String())
}
defer conn.Close()
buffer := make([]byte, 1024)
for {
conn.ReadFromUDP(buffer)
}
}()
wg.Wait()
}
}
但它不起作用。我能做些什么来使它工作?