I am a newbie for go and websockets. I am trying to take input character by character and writing them to websocket. I even want to take ctrl+c as input and write it to websocket.
func (c *poc) writePump() {
var err error
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
defer exec.Command("stty", "-F", "/dev/tty", "echo").Run()
var b = make([]byte, 1)
d := make(chan os.Signal, 1)
signal.Notify(d, os.Interrupt)
for {
os.Stdin.Read(b)
err = c.ws.WriteMessage(websocket.TextMessage, b)
if err != nil {
log.Printf("Failed to send UTF8 char: %s", err)
}
go func() {
for sig := range d {
// ????
}
}()
}
}
This code is capturing the signal but not sure how to write to websocket.