-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
50 lines (43 loc) · 1.33 KB
/
Copy pathtest.html
File metadata and controls
50 lines (43 loc) · 1.33 KB
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>websocket test</title>
<script type="text/javascript">
function WebSocketTest()
{
if ("WebSocket" in window)
{
// 打开一个 web socket
var ws = new WebSocket("ws://localhost:5000/core/websocket");
ws.onopen = function()
{
// Web Socket 已连接上,使用 send() 方法发送数据
ws.send("hello");
console.log("发送数据");
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
console.log("接收数据:",received_msg);
};
ws.onclose = function()
{
// 关闭 websocket
console.log("连接已关闭...");
};
}
else
{
// 浏览器不支持 WebSocket
alert("您的浏览器不支持 WebSocket!");
}
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:WebSocketTest()">运行 WebSocket</a>
</div>
</body>
</html>