-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat-client.html
37 lines (33 loc) · 996 Bytes
/
chat-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
37
<html>
<body>
<h1>Welcome to the chat</h1>
<label for="msg-input">Message:</label>
<input id="msg-input" name="msg-input" type="text" size="30" />
<p>Press enter to submit your message</p>
<ul id="broadcast-msg"></ul>
<script src="socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
var socket = io.connect('http://localhost:8020');
socket.on('connect', function ()
{
socket.emit('set nickname', prompt('What is your nickname?'));
$('#msg-input').change(function ()
{
var txt = $(this).val();
$(this).val('');
socket.emit('emit_msg', txt, function (data)
{
console.log('Emit msg', data);
})
})
});
socket.on('broadcast_msg', function (data)
{
console.log('Got msg:', data);
var msg = '<li>' + data + '</li>';
$('#broadcast-msg').append(msg);
})
</script>
</body>
</html>