-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (31 loc) · 901 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
35
36
var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
var app = express();
var httpServer = http.createServer(app);
var messages = [];
var io = require('socket.io')(httpServer);
var numClients = 0;
io.on('connection', function(client){
console.log('Client', numClients++, 'connected.');
client.on('join', function(data){
console.log(data);
});
client.on("chat", function(msg){
console.log(msg);
client.broadcast.emit('chat msg', msg);
});
});
app.use(bodyParser.json());
app.use(function(req, res,next){
console.log("Received", req.method, "request for resource",
req.path, "from", req.ip);
next();
});
//middleware to handle static content
app.use(express.static('src'));
//app.use(myLogStatement);
// server listen to port 3000 for incoming requests
httpServer.listen(3000, function(){
console.log("Listening on port 3000");
});