Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 12f61775e3
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (47 sloc) 1.705 kb
<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>
Jump to Line
Something went wrong with that request. Please try again.