forked from ericyanush/8Bit-Pic-Websockets
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebsocket_test.html
43 lines (34 loc) · 1.33 KB
/
websocket_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
43
<!DOCTYPE html>
<html>
<head>
<title>PIC WebSocket Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<script language="javascript" type="text/javascript">
var websocketUri = 'ws://192.168.0.199/';
function onLoad() {
result = document.createElement('div');
result.id = 'result';
result.innerHTML = '\<h1>PIC Websocket test\</h1>';
document.body.appendChild(result);
websocket = new WebSocket(websocketUri);
websocket.onmessage = function(event) {
result.innerHTML += '>>> ' + event.data + '\<br/>';
}
websocket.onopen = function(event) {
result.innerHTML += '+++ connection opened.\<br/>';
websocket.send('hello world');
result.innerHTML += '<<< hello world\<br/>';
};
websocket.onclose = function(event) {
result.innerHTML += '--- connection closed.\<br/>\<br/>';
};
websocket.onerror = function(event) {
result.innerHTML += 'Error: ' + event.data + '\<br/>';
};
}
window.addEventListener('load', onLoad, false);
</script>
</body>
</html>