JSFiddle - React, Tailwind, and code Playground

by denniswaltermartinez

HTML

<input type="text" id="txt"/>
<button>Send</button>

JavaScript

var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']);

// When the connection is open, send some data to the server
connection.onopen = function () {
  connection.send('helloz'); // Send the message 'Ping' to the server
};

// Log errors
connection.onerror = function (error) {
  console.log('WebSocket Error ' + error);
};

// Log messages from the server
connection.onmessage = function (e) {
  console.log('Server: ' + e.data);
};

$('button').click(function() {
    var val = $('#txt').val();
   connection.send(val);
});