Last active
August 18, 2018 12:08
-
-
Save apb2006/d82d0ca7aff6a9b2392f0c59f1f56ff3 to your computer and use it in GitHub Desktop.
BaseX web socket test https://github.com/BaseXdb/basex/issues/1449#issuecomment-413334902
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(:~ | |
: 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