-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
48 lines (46 loc) · 1.62 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
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<div>
<form>
<label for="numberfield">Number</label>
<input type="text" id="numberfield" placeholder="12"/><br />
<button type="button" id="sendBtn">Send</button>
</form>
</div>
<div id="container"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var ws;
if (window.WebSocket === undefined) {
$("#container").append("Your browser does not support WebSockets");
return;
} else {
ws = initWS();
}
function initWS() {
var socket = new WebSocket("ws://ec2-52-91-69-245.compute-1.amazonaws.com:5000/ws"),
container = $("#container")
socket.onopen = function() {
container.append("<p>Socket is open</p>");
};
socket.onmessage = function (e) {
// console.log("Adsasdasd",e.data)
container.append("<p> Got some shit:" + e.data + "</p>");
}
socket.onclose = function () {
container.append("<p>Socket closed</p>");
}
return socket;
}
$("#sendBtn").click(function (e) {
e.preventDefault();
ws.send(JSON.stringify({ Num: parseInt($("#numberfield").val()) }));
});
});
</script>
</body>
</html>