mirror of
https://github.com/kataras/iris.git
synced 2025-12-23 21:07:03 +00:00
Add some _examples in the main repository too.
Former-commit-id: 98895c34115ec2076b431332f0ffe9645adf7590
This commit is contained in:
29
_examples/examples/websockets/websockets.html
Normal file
29
_examples/examples/websockets/websockets.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user