title: How to keep a Kotlin Ktor websocket open
body: <p>Created a ktor server websocket endpoint.</p>
  <p>It refuses to stay open, despite being in a <code>while (true)</code> loop:</p>
  <p><strong>Server</strong></p>
  <pre><code>routing {
      webSocket(&quot;/data&quot;) {
          while (true) {
              send(Frame.Text(&quot;Howdy&quot;))
              delay(5000)
          }
      }
  }
  </code></pre>
  <p><strong>Client (Browser)</strong></p>
  <pre><code>const ws = new WebSocket(&quot;ws://www.example.com:1234/data&quot;)
  </code></pre>
  <p>Client (browser) connects, and receives the message, but then the socket closes.</p>
  <p>Why does this ws keep closing? I never issued a &quot;close&quot; command. How can I keep it open, so that new queued messages can be sent?</p>
  <p>Reference:
  <a href="https://ktor.io/docs/servers-features-websockets.html#usage" rel="nofollow noreferrer">https://ktor.io/docs/servers-features-websockets.html#usage</a></p>