-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (27 loc) · 736 Bytes
/
Copy pathindex.js
File metadata and controls
33 lines (27 loc) · 736 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
var express = require('express')
var app = express();
var http = require('http').Server(app)
var io = require('socket.io')(http)
app.use(express.static('assets'))
app.get('/',function(req,res){
res.sendFile(__dirname+'/index.html')
})
// app.set('port',3000)
app.set('port',process.env.PORT || 5000)
var user = 0
var msg = []
io.on('connection',function(socket){
user++
io.emit('userConnect',user)
console.log('+1 connected')
socket.on('disconnect', function (socket) {
user--
console.log('-1 connected')
io.emit('userConnect',user)
})
socket.on('addMsg',function(data){
msg.push(data)
io.emit('addMsg',data)
})
})
http.listen(app.get('port'),function(){console.log('listening on port 3000')})