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 pathindex.html
48 lines (45 loc) · 1.67 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
<!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</h1>
<p class="lead">This Sum server is a small TCP services that listens on one socket (27877) for the incoming data
(numbers 0...20), and sum all the valid inputs within a second (1000ms) to generate a sum result,
</p>
<hr class="my-4" />
<p>Please type next the value you want to sum</p>
</div>
<form action="">
<div class="form-group">
<input id="m" autocomplete="off" class="form-control" id="m" ></input>
</div>
<button type="submit" class="btn btn-primary">
Sum to server
</button>
</form>
</div>
<script src="http://localhost:27877/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();
// var socket = io.connect('http://localhost:27877');
var socket = io.connect('http://localhost:27877');
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('sum message', function(msg){
alert("please input a valid number: "+msg);
});
});
</script>
</body>
</html>