Added websocket examples for the server and client.
This commit is contained in:
15
library/network/websocket/client/www/index.html
Normal file
15
library/network/websocket/client/www/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WebSocket prototype</title>
|
||||
<script src="js/jquery-1.10.1.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WebSocket prototype</h1>
|
||||
<button id="run">Run</button>
|
||||
<p>Output :</p>
|
||||
<div id=console>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
9807
library/network/websocket/client/www/js/jquery-1.10.1.js
vendored
Normal file
9807
library/network/websocket/client/www/js/jquery-1.10.1.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
37
library/network/websocket/client/www/js/main.js
Normal file
37
library/network/websocket/client/www/js/main.js
Normal 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) };
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user