forked from colin29/game-lobby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
33 lines (30 loc) · 944 Bytes
/
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
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<link rel="stylesheet" type="text/css" href="index.css" media="screen" />
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val()); //1 extra argument here, means that function(msg) has 1 parameter, namely msg.
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
socket.on('system message', function(msg){
$('#messages').append($('<li>').text(msg).addClass('sysmsg'));
});
//socket.on and socket.emit on client side.
</script>
</body>
</html>