-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathws_client.html
33 lines (32 loc) · 974 Bytes
/
ws_client.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
<!--
Google BSD license https://developers.google.com/google-bsd-license
Copyright 2012 Google Inc. [email protected]
A minimal WebSocket client.
-->
<html><head><script type="text/javascript">
function WebSocketTest() {
if ("WebSocket" in window) {
var ws = new WebSocket("ws://localhost:8080/");
var count = 3;
ws.onopen = function() {
alert("Sending "+count);
ws.send("count["+count+"]");
};
ws.onmessage = function (evt) {
alert("Received ("+evt.data+"), sending "+
(count > 1 ? (count-1) : "close"));
if (count > 1) {
ws.send("count["+(--count)+"]");
} else {
ws.close();
}
};
ws.onclose = function() { alert("Closed"); };
ws.onerror = function(e) { alert("Error: "+e.data); };
} else {
alert("WebSocket NOT supported by your Browser!");
}
}
</script></head><body><div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket Test</a>
</div></body></html>