title: How to broadcast message using channel
body: <p>I am new to go and I am trying to create a simple chat server where clients can broadcast messages to all connected clients. </p>
  
  <p>In my server, I have a goroutine (infinite for loop) that accepts connection and all the connections are received by a channel. </p>
  
  <pre><code>go func() {
      for {
          conn, _ := listener.Accept()
          ch &lt;- conn
          }
  }()
  </code></pre>
  
  <p>Then, I start a handler (goroutine) for every connected client. Inside the handler, I try to broadcast to all connections by iterating through the channel. </p>
  
  <pre><code>for c := range ch {
      conn.Write(msg)
  }
  </code></pre>
  
  <p>However, I cannot broadcast because (I think from reading the docs) the channel needs to be closed before iterating. I am not sure when I should close the channel because I want to continuously accept new connections and closing the channel won't let me do that. If anyone can help me, or provide a better way to broadcast messages to all connected clients, it would be appreciated. </p>