Skip to content

Instantly share code, notes, and snippets.

@apb2006
Last active August 18, 2018 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apb2006/d82d0ca7aff6a9b2392f0c59f1f56ff3 to your computer and use it in GitHub Desktop.
Save apb2006/d82d0ca7aff6a9b2392f0c59f1f56ff3 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="BaseX socket test" />
<meta name="author" content="andy bunce." />
<title>BaseX Socket test v2</title>
</head
<body>
<h1>BaseX Socket test</h1>
<ul id="list" style="height:200px;">
</ul>
<script>
var msgId=0;
function log(msg){
console.log("LOG: ",msg);
var ul = document.getElementById("list");
var li = document.createElement("li");
li.appendChild(document.createTextNode(++msgId +" " + msg));
ul.appendChild(li);
};
var wsurl=('https:'==window.location.protocol?'wss:':'ws:')+'//'+ window.location.host +'/ws';
var exampleSocket = new WebSocket(wsurl, []);
exampleSocket.onopen = (event)=> log("open");
exampleSocket.onclose = (event) =>log("close");
exampleSocket.onmessage = (event) =>log("message");
exampleSocket.onerror = (event) =>log("error");
</script>
</body>
</html>
(:~
: websocket test
: @version 2
: @author apb 18aug 2018
:)
module namespace page = 'ws-test';
import module namespace ws = "http://basex.org/modules/Websocket";
declare
%ws:connect("{$path}")
function page:connect($path)
{
let $_:=trace(" SOCKET connect >>>",$path)
return ()
};
declare
%ws:error("{$path}","{$message}")
function page:error($path, $message)
{
let $_:=trace(" SOCKET error >>>",$path)
return ()
};
declare
%ws:message("{$path}","{$message}")
function page:message($path, $message)
{
let $_:=trace(" SOCKET message >>>",$path)
return ()
};
declare
%ws:close("{$path}")
function page:close($path)
{
let $_:=trace(" SOCKET close >>>",$path)
return ()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment