I'm a newcomer for the golang and websocket.
I'm trying to write a websocket server which can send the messages actively to client once the handshake is done.
but my server will just only send the message to the client when got the request from the client.
Does anyone know how to implement this feature or where can I find the related answer for that?
Thank you so much.
the source code is as follows:
package main
import (
"log"
"net/http"
)
func handler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("Hi, the handshake is completed.
"))
w.Write([]byte("Let's start to talk something.
"))
}
func main() {
http.HandleFunc("/", handler)
log.Printf("Start to listen on 443.")
err := http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
log.Fatal(err)
}