-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
49 lines (47 loc) · 1.23 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>chat</title>
<style>
.chat_log{ width: 95%; height: 200px;}
.name{ width: 10%; }
.message{ width: 70%; }
.chat{ width: 10%;}
</style>
</head>
<body>
<div>
<textarea id="chatLog" class="chat_log" readonly></textarea>
</div>
<form id="chat">
<input id="name" class="name" type="text" readonly>
<input id="message" class="message" type="text">
<input type="submit" class="chat" value="chat"/>
</form>
<div id="box" class="box">
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
$('#chat').on('submit', function(e){
socket.emit('send message', $('#name').val(), $('#message').val());
$('message').val('');
e.preventDefault();
});
// 이벤트를 받을 때는 socket.on으로 받는다.
// 이벤트이름, 오브젝트
socket.on('welcome',function(data){
$('#chatLog').append(data.msg + '\n');
});
socket.on('receive message', function(msg){
$('#chatLog').append(msg + '\n');
$('#chatLog').scrollTop($('#chatLog').innerHeight());
});
socket.on('change name' , function(name){
$('#name').val(name);
});
</script>
</div>
</body>
</html>