-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
62 lines (55 loc) · 1.59 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
var reader = {
readAs: function(type,blob,cb){
var r = new FileReader();
r.onloadend = function(){
if(typeof(cb) === 'function') {
cb.call(r,r.result);
}
}
try{
r['readAs'+type](blob);
}catch(e){}
}
}
function parseBlob(blob){
var stringVar;
reader.readAs('Text',blob.slice(16,blob.size,'text/plain;charset=UTF-8'),function(result){
stringVar = result;
console.log(stringVar);
$(document).ready(function(){
$("ol").append( "<li>" + stringVar + "</li>");
});
});
}
// 打开一个 web socket
var ws = new WebSocket("ws://127.0.0.1:8999");
ws.onopen = function()
{
// Web Socket 已连接上,使用 send() 方法发送数据
console.log('ok');
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
parseBlob(received_msg);
};
ws.onclose = function()
{
// 关闭 websocket
alert("连接已关闭...");
};
</script>
</head>
<body>
<div id="sse">
test
</div>
<ol><li>list<li</ol>
</body>
</html>