-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (28 loc) · 806 Bytes
/
server.js
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
var express = require('express');
var http = require('http');
var app = express();
var server = http.Server(app);
var io = require('socket.io')(server);
app.set('view engine', 'ejs');
app.use('/a', express.static( __dirname.concat('/public/') ));
app.get('/',function(req,res){
res.render('index');
});
io.on('connection',function(socket){
io.emit('message', {
date: new Date(),
body: "User in"
});
socket.on('message',function(msg){
io.emit('message',msg);
});
socket.on('disconnect',function(){
io.emit('message', {
date: new Date(),
body: "User disconnected"
});
});
});
var ip = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1',
port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
server.listen(port,ip);