iris/_examples/intermediate/websockets/ridiculous-simple/websockets.html
Gerasimos (Makis) Maropoulos 7c5d7cae05 Add More Examples & Categorized in Folders & TOC
Part 2.


Former-commit-id: 3ccb7c259e86c0b6e5147d372aa9cff10c1b5bb1
2017-03-24 00:25:59 +02:00

30 lines
757 B
HTML

<input id="input" type="text" />
<button onclick="send()">Send</button>
<pre id="output"></pre>
<script src="/iris-ws.js"></script>
<script>
var input = document.getElementById("input");
var output = document.getElementById("output");
// Ws comes from the auto-served '/iris-ws.js'
var socket = new Ws("ws://localhost:8080/echo");
socket.OnConnect(function () {
output.innerHTML += "Status: Connected\n";
});
socket.OnDisconnect(function () {
output.innerHTML += "Status: Disconnected\n";
});
// read events from the server
socket.On("chat", function (msg) {
output.innerHTML += "Server: " + msg + "\n";
});
function send() {
// send chat event data to the server
socket.Emit("chat", input.value);
input.value = "";
}
</script>