-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
39 lines (29 loc) · 1008 Bytes
/
app.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
37
38
//requiring Express
var express = require('express');
//creating a new server
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
//setting the static folder to node_modules
app.use(express.static(__dirname + '/node_modules'));
//routes http requests to the speicified path
//with a specific call back function
//The 'res' object represents the HTTP response
//that an Express app sends when it gets a request.
app.get('/', function(req, res, next) {
//sends the file at the specific path
res.sendFile(__dirname + '/index.html')
});
//io.on is listening for connections
io.on('connection', function(client) {
console.log('Client connected...');
client.on('join', function(data) {
console.log(data);
});
client.on('messages', function(data) {
client.emit('broad', data);
client.broadcast.emit('broad',data);
});
});
//opens a port and listen for requests coming in
server.listen(4200);