-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolveChatRoom.node.js
More file actions
43 lines (35 loc) · 942 Bytes
/
solveChatRoom.node.js
File metadata and controls
43 lines (35 loc) · 942 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/im too tired ill be back in an hour/
var http = require("http");
var express = require("express");
var io = require("socket").io;
var router = express();
var server = http.createServer(router);server.listen(80);
var socket = io(server);
var messages = [];
var clients = [];
socket.on('connection', function(socket){
clients.push(socket);
var name;
socket.on('message', function(data){
for(var i = 0; i<clients.length;i++){
clients[i].emit('message', data);
};
})
socket.on('join', function(data) {
name = data.name;
for(var i= 0;i<clients.length;i++){
clients[i].emit('join', {
"name":name
})
}
})
socket.on('disconnect', function(){
for(var i=0;i<clients.length; i++)
clients[i].emit('exit',{
"name":name
})
})
});
router.get('/', function (req,res) {
res.send("Hello world");
});