aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/wstest.html
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2013-05-11 11:57:56 +0800
committerpzread <netfirewall@gmail.com>2013-05-11 11:57:56 +0800
commit517796ece5cc21ad24e06438cfeacc9cf770ad64 (patch)
treeef0aa515c16fd0e1fc899ecf8b7ccf4e1cd62a1b /src/test/wstest.html
parent4b2c34236ee67a44573a538497ecc166f0c65897 (diff)
downloadtaiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar.gz
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar.bz2
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar.lz
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar.xz
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.tar.zst
taiwan-online-judge-517796ece5cc21ad24e06438cfeacc9cf770ad64.zip
Test websocket IMC
Diffstat (limited to 'src/test/wstest.html')
-rw-r--r--src/test/wstest.html84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/test/wstest.html b/src/test/wstest.html
new file mode 100644
index 0000000..be144b4
--- /dev/null
+++ b/src/test/wstest.html
@@ -0,0 +1,84 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script type="text/javascript" src="/jquery-1.9.1.min.js"></script>
+<script type="text/javascript">
+var count = 0;
+var last = 0;
+var data = new ArrayBuffer(1024);
+
+function test(){
+ $.post('http://toj.tfcis.org:83/conn',{},function(res){
+ var reto;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res)
+ conn(reto.client_linkid,reto.worker_linkid,reto.ip,reto.port);
+ }else{
+
+ }
+ });
+}
+
+function conn(client_linkid,worker_linkid,ip,port){
+ console.log(client_linkid);
+ console.log(worker_linkid);
+
+ var ws;
+ var reader = new FileReader;
+ var imc_call = function(iden,dst,func_name,param){
+ call = {
+ 'type':'call',
+ 'caller_genid':13,
+ 'timeout':60000,
+ 'iden':iden,
+ 'dst':dst,
+ 'func_name':func_name,
+ 'param':param
+ }
+
+ data = new Blob([JSON.stringify(call)],{'type':'application/octet-stream'})
+ ws.send(data);
+ };
+
+ ws = new WebSocket('ws://' + ip + ':' + port + '/conn');
+ ws.onopen = function(){
+ var i;
+
+ console.log('open');
+ ws.send(JSON.stringify({
+ 'client_linkid':client_linkid
+ }))
+
+ imc_call(client_linkid,'/backend/' + worker_linkid,'test_dst','Hello');
+ };
+ ws.onmessage = function(e){
+ reader.onload = function(e){
+ var res = e.target.result;
+ //console.log(JSON.parse(res));
+
+ imc_call(client_linkid,'/backend/' + worker_linkid,'test_dst','Hello');
+ };
+ reader.readAsText(e.data);
+ count++;
+ };
+
+ perf();
+}
+
+function perf(){
+ $('#speed').text((count - last) + '/s');
+ last = count;
+ setTimeout(perf,1000);
+}
+
+$(document).ready(function(){
+ test();
+});
+
+</script>
+</head>
+<body>
+<h1 id = "speed">0</h1>
+</body>
+</html>