I am trying to send a broadcast message to clients using websockets. How to fix this code to send message properly to all clients and without that error?
package main
import (
"fmt"
"golang.org/x/net/websocket"
"net/http"
)
var connections []websocket.Conn
func main() {
fmt.Println("vim-go")
http.Handle("/", websocket.Handler(Server))
err := http.ListenAndServe(":8888", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
func Server(ws *websocket.Conn) {
lll := append(connections, *ws)
var message string
websocket.Message.Receive(ws, &message)
fmt.Println(message)
for ccc := range connections {
websocket.Message.Send(ccc, "Another connection!!!")
}
}