-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.html
42 lines (36 loc) · 1.16 KB
/
test.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
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<meta charset="utf-8">
<head>
<title>WebSocket Test</title>
<script type="text/javascript" src="jsbn.min.js" ></script>
<script type="text/javascript" src="sjcl.min.js" ></script>
<script type="application/javascript">
var ws = new WebSocket("ws://127.0.0.1:9999/test");
ws.onmessage=function(msg){
document.getElementById("res").value = document.getElementById("res").value+msg.data+"\r\n";
}
function send(){
ws.send(document.getElementById("msg").value);
}
var reader = new FileReader();
reader.onload=function(e){
ws.send(e.target.result);
}
function upload(e){
if(e.files.length==1){
var file = e.files[0];
reader.readAsArrayBuffer(file);
}
}
</script>
</head>
<body>
websocket发送文本:<input type="text" value="test" id="msg">
<input type="button" value="send" onclick="send()">
<br><br>
websocket发送文件:<input type="file" value="websocket upload" onchange="upload(this)">
<br><br>
<textarea id="res" rows="50" cols="50"></textarea>
</div>
</body>
</html>