-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (29 loc) · 1.4 KB
/
server.js
File metadata and controls
43 lines (29 loc) · 1.4 KB
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
/* ********************************************************
This is the Server File for ABG Reports Web applications
******************************************************** */
var express = require('express'), //Get the EXPRESS Module
app = express(); //Define an express application handler
var http = require('http'), //Get the HTTP Module
server = http.createServer(app); //Create a http server app for Chat application of scoket io
var path = require('path');
var io = require('socket.io').listen(server); // io - this is a socket io listener for a http server
/* Serve Static files from /Client folder */
app.use(express.static(__dirname + '/client'));
/* Express Route for home page */
app.get('/',function(req,res){
res.sendFile(__dirname + '/client/index.html');
});
/* Socket.io connection event and corresponding call-back function for listening further message events on socket */
io.on('connection', function(socket){
/* Listen the send event for incoming messages on the server */
socket.on('sendevent',function(data){
console.log(data);
/* Emit the rec event for incoming messages on the server */
io.emit('recevent',data);
});
console.log('a user connected');
});
/* NOTE: You can't listen on an express app as app.listen(). You need to listen on pure http server as server.listen() */
server.listen(process.env.PORT || 3030,function(){
console.log('Listening on port 3030');
});