-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathwebsocket.html
53 lines (38 loc) · 987 Bytes
/
websocket.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
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function() {
var uri= window.location.host + window.location.pathname + 'ws'
if (window.location.protocol === 'http:') {
new_uri = "ws:"+uri;
} else {
new_uri = "wss:"+uri;
}
var ws;
if ('WebSocket' in window) {
ws = new WebSocket(new_uri);
}
else if ('MozWebSocket' in window) {
ws = new MozWebSocket(new_uri);
}
else {
alert("<tr><td> your browser doesn't support web socket </td></tr>");
return;
}
ws.onopen = function(evt) {
$("#idlogs").append("Connection open ...\n")
};
ws.onmessage = function(evt){
$("#idlogs").append(" New message..." + evt.data + '\n')
};
function closeConnect(){
ws.close();
}
});
</script>
</head>
<body>
<textarea id="idlogs" cols='60' rows='8'>...</textarea>
</body>
<html>