JSFiddle - React, Tailwind, and code Playground

by HugeHugh

HTML

<form onsubmit="return sendTxt()">
<input type="text" id="words" value="hello world"/>
<input type="submit" value="send" />
</form>

JavaScript

function message(msg) {
    console.log(msg);
}
function sendTxt() {
    socket.send(document.getElementById('words').value);
    return false;
}
var socket;
try {
    socket = new WebSocket("wss://smartjs-programico.dotcloud.com",  "echo-protocol");
    message('SKT new, status=' + socket.readyState);
    socket.onopen = function () {
        message('SKT open, status=' + socket.readyState);
        socket.send("I send to echo server when I open!")
    }
    socket.onmessage = function (msg) {
        message('SKT message, data=' + msg.data);
        alert("RECEIVED SERVER ECHO\n" + msg.data)
    }
    socket.onclose = function () {
        message('SKT close, status=' + socket.readyState);
    }
} catch (exception) {
    message('SKT error, exception=' + exception);
}