-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
44 lines (34 loc) · 887 Bytes
/
index.html
File metadata and controls
44 lines (34 loc) · 887 Bytes
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
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
<h3>WebSocket Go</h3>
<input type="text" id="msg_input">
<input type="button" onclick="sendMsg()" value="发送">
<pre id="output"></pre>
<script>
url = 'ws://127.0.0.1:12312/ws';
c = new WebSocket(url);
send = function(data){
$("#output").append((new Date())+ " ==> "+data+"\n")
c.send(data)
}
c.onmessage = function(msg){
$("#output").append((new Date())+ " <== "+msg.data+"\n")
console.log(msg)
}
// c.onopen = function(){
// setInterval(
// function(){
// send("ping")
// }
// , 3000 )
// }
function sendMsg(){
var msg = document.getElementsByTagName("input")[0].value
send(msg)
}
</script>
</body>
</html>