score:1

Accepted answer
<html>
  <script>
    var ws = new WebSocket("ws://localhost:3000/");

    ws.onopen = function() {
      // Sends a message
      ws.send("ping");  
    };

    ws.onmessage = function(e) {
      // Receives a message.
      alert(e.data);
    };

    ws.onclose = function() {
      alert("closed");
    };
  </script>
</html>

Related Query

More Query from same tag