title: Is it possible to run http.ListenAndServe() AND ReadFromUDP() concurrently?
body: <p>I am trying to write a simple web app that will listen for UDP packets.</p>
  
  <p>But I can either only listen for UDP packets, or run the web app... 
  I am not familiar with GoLang, but here's the code I'm using to...
  listen for UDP:</p>
  
  <pre><code> ServerConn, _ := net.ListenUDP("udp", &amp;net.UDPAddr{IP:[]byte{#,#,#,#},Port:####,Zone:""})
    defer ServerConn.Close()
    buf := make([]byte, 1024)
  
    for {
      n, addr, _ := ServerConn.ReadFromUDP(buf)
      fmt.Println("Received ", string(buf[0:n]), " from ", addr)
    }
  </code></pre>
  
  <p>Server logic:</p>
  
  <pre><code>    package main
  We import 4 important libraries 
  1. “net/http” to access the core go http functionality
  2. “fmt” for formatting our text
  3. “html/template” a library that allows us to interact with our html file.
  4. "time" - a library for working with date and time.
  import (
     "net/http"
     "fmt"
     "time"
     "html/template"
  )
  
  //Create a struct that holds information to be displayed in our HTML file
  type Welcome struct {
     Name string
     Time string
  }
  
  //Go application entrypoint
  func main() {
     //Instantiate a Welcome struct object and pass in some random information. 
     //We shall get the name of the user as a query parameter from the URL
     welcome := Welcome{"Anonymous", time.Now().Format(time.Stamp)}
  
     //We tell Go exactly where we can find our html file. We ask Go to parse the html file (Notice
     // the relative path). We wrap it in a call to template.Must() which handles any errors and halts if there are fatal errors
  
     templates := template.Must(template.ParseFiles("templates/welcome-template.html"))
  
     //Our HTML comes with CSS that go needs to provide when we run the app. Here we tell go to create
     // a handle that looks in the static directory, go then uses the "/static/" as a url that our
     //html can refer to when looking for our css and other files. 
  
     http.Handle("/static/", //final url can be anything
        http.StripPrefix("/static/",
           http.FileServer(http.Dir("static")))) //Go looks in the relative "static" directory first using http.FileServer(), then matches it to a
           //url of our choice as shown in http.Handle("/static/"). This url is what we need when referencing our css files
           //once the server begins. Our html code would therefore be &lt;link rel="stylesheet"  href="/static/stylesheet/..."&gt;
           //It is important to note the url in http.Handle can be whatever we like, so long as we are consistent.
  
     //This method takes in the URL path "/" and a function that takes in a response writer, and a http request.
     http.HandleFunc("/" , func(w http.ResponseWriter, r *http.Request) {
  
        //Takes the name from the URL query e.g ?name=Martin, will set welcome.Name = Martin.
        if name := r.FormValue("name"); name != "" {
           welcome.Name = name;
        }
        //If errors show an internal server error message
        //I also pass the welcome struct to the welcome-template.html file.
        if err := templates.ExecuteTemplate(w, "welcome-template.html", welcome); err != nil {
           http.Error(w, err.Error(), http.StatusInternalServerError)
        }
     })
  
     //Start the web server, set the port to listen to 8080. Without a path it assumes localhost
     //Print any errors from starting the webserver using fmt
     fmt.Println("Listening");
     fmt.Println(http.ListenAndServe(":8080", nil));
  }
  </code></pre>
  
  <p>taken from(<a href="https://medium.com/google-cloud/building-a-go-web-app-from-scratch-to-deploying-on-google-cloud-part-1-building-a-simple-go-aee452a2e654" rel="nofollow noreferrer">https://medium.com/google-cloud/building-a-go-web-app-from-scratch-to-deploying-on-google-cloud-part-1-building-a-simple-go-aee452a2e654</a>)</p>
  
  <p>I tried putting both of these extracts in 1 file, as well as running 2 files at the same time using </p>
  
  <pre><code>go run *.go
  </code></pre>
  
  <p>Any help would be appreciated!</p>