-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebSocketEcho.html
46 lines (37 loc) · 1.66 KB
/
WebSocketEcho.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Web Socket - connection with test websocket</title>
<script>
var wsUri = 'ws://echo.websocket.org';
//var wsUri = 'ws://localhost:57772/chattalktome/talk2me.web.websocketEcho.cls';
console.log("wsUri = " + wsUri);
if ('WebSocket' in window)
{
console.log("the browser supports webSockets");
var ws = new WebSocket(wsUri);
console.log("trying to connect to webSocket server");
ws.onopen = function(event) {
console.log("we are connected to ECHO websocket server, the data from it: " + event.data);
console.log("we send the messege to ECHO websocket server: Hello Web Socket!");
ws.send("Hello Web Socket!");
};
ws.onmessage = function(event) {
console.log("we've got the messege from ECHO websocket server, data: " + event.data);
console.log("we send request to close connection");
ws.close();
};
ws.onclose = function(event) {
console.log("connection is closed, data: " + event.data);
};
ws.onerror = function(error) {
console.log("Error: " + error.message + ".");
};
} else console.log("the browser does not support webSockets");
</script>
</head>
<body>
<p>All results you can see in the console of the browser (F12).</p>
</body>
</html>