Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sorry for the comment in the form of an answer, I can't comment yet...</p> <p>Are you setting Sec-WebSocket-Protocol header on the websocket Config? (<a href="https://code.google.com/p/go/source/browse/websocket/websocket.go?repo=net#74" rel="nofollow">https://code.google.com/p/go/source/browse/websocket/websocket.go?repo=net#74</a> and <a href="http://tools.ietf.org/html/rfc6455#page-59" rel="nofollow">http://tools.ietf.org/html/rfc6455#page-59</a>)</p> <p>That error message seems to crop up on Google many times relating to incompatibility or conflict with that header.</p> <p>Something like:</p> <pre><code>func wsHandler(webSck *websocket.Conn) { webSck.Config.Header.Add("Sec-WebSocket-Protocol", "chat") fmt.Fprint(webSck, "Rpy") fmt.Println("Sent \"Rpy\" to web socket", webSck) //more code here } </code></pre> <p>Also, I think it's preferred to use the Write function on the websocket (<a href="https://code.google.com/p/go/source/browse/websocket/websocket.go?repo=net#205" rel="nofollow">https://code.google.com/p/go/source/browse/websocket/websocket.go?repo=net#205</a>) as it encapsulates/converts the written data into frames.</p> <p>So more like:</p> <pre><code>func wsHandler(webSck *websocket.Conn) { webSck.Config.Header.Add("Sec-WebSocket-Protocol", "chat") _, _ = webSck.Write("Rpy") fmt.Println("Sent \"Rpy\" to web socket") //more code here } </code></pre> <p>But obviously checking the error from Write!</p> <p>Hope that helps.</p> <p>EDIT: Remove the extraneous ", webSck" from the fmt.Println .</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload