Everything works fine with this code (shortened for better reading).
When it Client1sends a request to the server, the server instantly responds to it. But other clients cannot see the response message.
So, I want to do this further: when a client sends a request to the server, the server will respond to all clients so that all clients can see this message.
How can i do this? Any examples or good primers?
Thanks in advance!
Server:
import (
"github.com/gorilla/websocket"
)
func main() {
http.Handle("/server", websocket.Handler(echoHandler))
}
func echoHandler(ws *websocket.Conn) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
for {
messageType, p, err := conn.ReadMessage()
if err != nil {
return
}
print_binary(p)
err = conn.WriteMessage(messageType, p);
if err != nil {
return
}
}
}
source
share