-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
51 lines (48 loc) · 1.31 KB
/
index.html
File metadata and controls
51 lines (48 loc) · 1.31 KB
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
50
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>
First Node/Socket
</title>
<!-- <script src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script> -->
<script src="http://173.255.232.46/js/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
var socket = new io.Socket('173.255.232.46');
socket.connect();
//socket.on('connect', function(){ alert('client connected'); });
socket.on('message',
function(msg){
switch(msg.type){
case "message":
$('#content').append(msg.uid+" : "+msg.content+"<br/>");
break;
case "connect":
$('#content').append(msg.uid+" has joined. <br/>");
break;
case "disconnect":
$('#content').append(msg.uid+" has left. <br/>");
break;
}
}
);
function sendMsg(message){
socket.send(message);
}
// socket.on('message', function(){ . })
// socket.on('disconnect', function(){ . })
</script>
</head>
<body>
<h1>
Hello, World!
</h1>
<input type='text' onkeydown="if(event.keyCode==13){sendMsg(this.value);this.value=''}">
</input>
This is a chat window.<br/>
<div id="chatList">
</div>
<div id="content" style="border-top:1px solid #000;">
</div>
</body>
</html>