Added websocket examples for the server and client.

This commit is contained in:
2016-10-13 22:01:50 +02:00
parent 1e4203111f
commit 01a9d02586
18 changed files with 10562 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
$(function() {
var wsEchoURI = "ws://localhost:9999/";
var websocket;
function printConsole(text) {
$("#console").append($(document.createElement("p")).html(text));
}
function onWSOpen(evt) {
printConsole("WebSocket open");
if(websocket.readyState == websocket.OPEN) {
printConsole("WebSocket ready");
}
}
function onWSClose(evt) {
printConsole("WebSocket closed");
printConsole(websocket.readyState);
}
function onWSMessage(evt) {
printConsole(evt.data);
}
function onWSError(evt) {
printConsole("An error occured in the WebSocket : " + evt.data);
}
$("#run").click(function buttonRun() {
printConsole("Connection");
websocket = new WebSocket(wsEchoURI);
websocket.onopen = function(evt) { onWSOpen(evt) };
websocket.onclose = function(evt) { onWSClose(evt) };
websocket.onmessage = function(evt) { onWSMessage(evt) };
websocket.onerror = function(evt) { onWSError(evt) };
});
});