title: Gorilla websocket error: close 1007 Illegal UTF-8 Sequence
body: <p>I'm trying to implement a websocket proxy server for GlassFish. If I try to connect more than one client I'm getting error:</p>
  
  <blockquote>
    <p>ReadMessage Failed:  websocket: close 1007 Illegal UTF-8 Sequence.</p>
  </blockquote>
  
  <p>I'm sure the GlassFish server sending right data, because the same server works properly with another proxy server implemented with node.js.</p>
  
  <pre><code>func GlassFishHandler(conn *websocket.Conn){
  
      defer conn.Close()
  
      conn.SetReadDeadline(time.Now().Add(1000 * time.Second))
      conn.SetWriteDeadline(time.Now().Add(1000 * time.Second))
  
      fmt.Println("WS-GOLANG PROXY SERVER: Connected to GlassFish")
  
      for {
  
          messageType, reader, err := conn.NextReader()
  
          if err != nil {
              fmt.Println("ReadMessage Failed: ", err) // &lt;- error here
          } else {
  
              message, err := ioutil.ReadAll(reader)
              if (err == nil &amp;&amp; messageType == websocket.TextMessage){
  
                  var dat map[string]interface{}
                  if err := json.Unmarshal(message, &amp;dat); err != nil {
                      panic(err)
                  } 
  
                  // get client destination id
                  clientId := dat["target"].(string)
  
                  fmt.Println("Msg from GlassFish for Client: ", dat);
  
                  // pass through
                  clients[clientId].WriteMessage(websocket.TextMessage, message)
              }
          }
      }
  }
  </code></pre>