listener, err := net.Listen("tcp", "localhost:8080") if err != nil { log.Fatal(err) } defer listener.Close()
conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: 8080}) if err != nil { log.Fatal(err) } defer conn.Close()In this example, a UDP listener is created on port `8080`. The `defer` statement ensures that the listener is closed when the function exits. In both examples, the `Close()` method is used to gracefully shut down the listener, which releases any open resources and prevents any new connections from being accepted. The `net` package is included in the standard library of Go.