-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
38 lines (38 loc) · 936 Bytes
/
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
<!doctype html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
if ("WebSocket" in window) {
var ws = new WebSocket("ws://host_here:port_here/");
ws.onopen = function() {
$('#wait').html("you can type and hit enter. look at your console.")
$('#form').submit(function(){
ws.send($('#message').val())
$('#message').val('')
return false;
})
ws.send("message to send");
};
ws.onmessage = function (evt) {
var m = evt.data;
$('#message').after("<div class='message'>"+m+"</div>")
};
ws.onclose = function() {
alert("closed")
};
} else {
alert("No web socket support"); //flash alternative ?
}
})
</script>
</head>
<body>
<div id="wait">Waiting...</div>
Web socket
<form id="form" action="http://www.google.com">
<input id="message">
</form>
</body>
</html>