JSFiddle - React, Tailwind, and code Playground
by boulabiar
HTML
<input type="text" id="txt" />
<br/>
<textarea rows="24" cols="80" id="area">
</textarea>
JavaScript
var state=document.getElementById("txt");
var val=document.getElementById("area");
var ws = new WebSocket("ws://localhost:1234");
ws.onopen = function(evt) {
state.value = "connection open" ;
ws.send(val.value);
};
ws.onmessage = function(evt) {
area.value = area.value + " " + evt.data;
if (area.value.length > 1800) area.value="";
}
ws.onclose = function(evt) {
state.value = "Connection closed.";
}
// http://stackoverflow.com/questions/19542333/websocket-server-sending-messages-periodically-in-python