This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisten.html
49 lines (45 loc) · 1.64 KB
/
listen.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
<!doctype html>
<html>
<head>
<title>Socket.IO sum Server</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css">
</head>
<body>
<div class="container card">
<div class="jumbotron">
<h1 class="display-4">Sum Server listener</h1>
<p class="lead">Socket in (27878) that show the sum result is sent to any client listening to that port.</p>
<hr class="my-4" />
<p>Please type next the value you want to sum</p>
</div>
<div class="form-group">
<ul id="messages"></ul>
</div>
<div class="form-group">
<label for="staticEmail" class="col-sm-2 col-form-label">Sum results</label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" id="sumResults" value="0">
</div>
</div>
</div>
<script src="http://localhost:27878/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/js/bootstrap.js"></script>
<script>
$(function () {
var socket = io.connect('http://localhost:27878');
socket.on('sum message', function(msg){
try {
let sumValue = parseInt(msg);
let res = parseInt($("#sumResults").val()) + sumValue;
$("#sumResults").val(res);
$('#messages').append($('<li>').text(msg));
}
catch(err) {
alert("error listening: "+err);
}
});
});
</script>
</body>
</html>