title: How to keep a websocket connection in OPEN readystate after send?
body: <p>I am new to websockets.  </p>
  
  <p>In my setup I have a trivial websocket server written in Go (<a href="https://play.golang.org/p/H6ctw_tFlx" rel="nofollow noreferrer">playground</a>)</p>
  
  <p>I make a <code>WebSocket</code> object, set up its <code>onmessage</code> callback and call its <code>send</code> method to test.</p>
  
  <pre><code>var w = new WebSocket("ws://localhost:12345/echo")
  
  w.onmessage = (msg) =&gt; {
     console.log(msg.data)
  }
  
  w.onopen = () =&gt; {
     w.send("Hello")  // this fires OK
  }
  </code></pre>
  
  <p>What I expect to happen based on the server code is to receive the "Hello" message and to keep sending "yahoo" every 1.5s to the client.  What actually happens is "Hello" is sent, but none of the "yahoo"'s make it thru.  It seems somewhere along the WebSocket.readystate becomes 3 (CLOSED).  </p>
  
  <p>To clarify, the server receives and prints "Hello" then actually fires a "yahoo" message every 1.5s, but the connection is closed by then so the <code>onmessage</code> callback never fires.</p>
  
  <p>Am I missing or misunderstanding anything? </p>
  
  <p>EDIT: Ran across <a href="https://github.com/gorilla/websocket#gorilla-websocket-compared-with-other-packages" rel="nofollow noreferrer">comparison github.com/gorilla vs. golang.org/x/net</a>, claims golang.org/x/net websocket implementation does not support pong.  This may be the confirmation of it.</p>
  
  <p>EDIT: Package golang.org/x/net/websocket closes the websocket connection when the handler ServeHTTP function returns.  By default a websocket connection is tied to an instance of the handler.</p>