-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocket.html
More file actions
29 lines (24 loc) · 711 Bytes
/
socket.html
File metadata and controls
29 lines (24 loc) · 711 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>This is Socket.io</title>
<script src="/socket.io/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
</head>
<body>
<div id="div1"> </div>
<textarea id="text"></textarea>
<script>
var socket = io.connect();
socket.on('message',function(data){
console.log(data.message);
document.getElementById('div1').innerHTML=data.message;
});
$('#text').keypress(function(e){
socket.emit('client_data',{'letter': String.fromCharCode(e.charCode)});
console.log(String.fromCharCode(e.charCode));
});
</script>
</body>
</html>