-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
36 lines (36 loc) · 1002 Bytes
/
client.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
<html>
<head>
<!-- Include socket.io from node_modules -->
<script src="/socket.io/socket.io.js"></script>
<!-- Include jquery from google CDN -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<script>
//Declare socket.io variable.
var socket = io.connect();
//Receive message from server(via web socket).
socket.on('date', function(data) {
$('#date').text(data.date);
});
$(document).ready(function(){
$('#text').keypress(function(e) {//Monitor keyboard character.
//Send message to server(via web socket).
socket.emit('clientData', {
'letter' : String.fromCharCode(e.charCode),
'content' : $('#text').val()
});
});
//Use button submit socket message.
$('#submit').click(function () {
socket.emit('clientData', {
'content' : $('#text').val()
})
});
});
</script>
<div id="date"></div>
<textarea id="text"></textarea>
<button id = "submit">submit</button>
</body>
</html>