-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
51 lines (44 loc) · 1.3 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Websocket Example</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
function log(message) {
$('#console').append(message + '\n');
}
$(window).ready(function() {
var echo_url = window.location.href.replace('http://', 'ws://') + 'echo';
var connection = new WebSocket(echo_url);
connection.onopen = function() {
log('[*] connected');
}
connection.onerror = function(err) {
log('[!] error: ' + err);
}
connection.onmessage = function(message) {
log('[ ] received: ' + message.data);
}
log('[*] opening: ' + echo_url);
$('#input').focus();
$('#input').on('keypress', function(e) {
if (e.keyCode == 13) {
var message = $('#input').val()
log('[ ] sending: ' + message);
connection.send(message);
$('#input').val('');
}
});
});
</script>
<style>
#console { font-family: monospace }
</style>
</head>
<body>
<h1>Websocket Example</h1>
<textarea rows="20" cols="80" id="console"></textarea>
<br/>
<input type="text" id="input" size="100" placeholder="Type Here..." />
</body>
</html>