This repository was archived by the owner on Mar 1, 2024. It is now read-only.
forked from rlotun/txWebSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.html
51 lines (47 loc) · 1.67 KB
/
echo.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>
<title>WebSocket example: echo service</title>
</head>
<body>
<h1>WebSocket example: echo service</h1>
<script type="text/javascript">
var Socket = window.WebSocket;
if ("MozWebSocket" in window) {
Socket = window.MozWebSocket
}
var ws = new Socket("ws://" + window.location.hostname + ':' + window.location.port + "/echo");
ws.onmessage = function(evt) {
var data = evt.data;
var target = document.getElementById("received");
target.value = target.value + data;
};
ws.onopen = function(evt) {
var target = document.getElementById('conn_status');
target.value = "Connected";
};
ws.onerror = function(evt) {
target = document.getElementById('conn_status');
target.value = 'Error';
};
ws.onclose = function(evt) {
target = document.getElementById('conn_status');
target.value = 'Closed';
};
window.send_data = function() {
ws.send(document.getElementById("send_input").value);
};
</script>
<form>
<label for="send_input">Text to send</label>
<input type="text" name="send_input" id="send_input"/>
<input type="submit" name="send_submit" id="send_submit" value="Send"
onclick="send_data(); return false"/>
<br/>
<label for="received">Received text</label>
<textarea name="received" id="received"></textarea>
<br/>
<label for="status">Status</label>
<input type="text" name="status" id="conn_status" value="Not Connected"/>
</form>
</body>
</html>