I`m using this node base: https://github.com/jessereitsma/node-base
and I`m using websockets: https://github.com/einaros/ws
This is my code in app.js:
var express = require('express')
, http = require('http')
, path = require('path')
, app = express()
, fs = require('fs')
, engine = require('ejs-locals')
, webSocket = require('ws').Server;
app.set('port', 80);
app.set('wsPort', 8080);
app.set('views', __dirname + '/views');
app.engine('ejs', engine);
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('[secret]'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
fs.readdirSync('./controllers').forEach(function (controller) {
if(controller.substr(-3) == '.js') {
route = require('./controllers/' + controller);
route.controller(app);
}
});
var wss = new webSocket({port:app.get('wsPort')});
wss.on('connection', function(ws) {
console.log('NEW CONNECTION');
});
http.createServer(app).listen(app.get('port'), function(){
console.log('Server runs at port: ' + app.get('port'));
console.log('Websocket server runs at port ' + app.get('wsPort'));
});
And when I want to connect I open the console log and type this:
new WebSocket('ws://dylan.jrnode.eu:8080');
output:
WebSocket {binaryType: "blob", extensions: "", protocol: "", onclose: null, onerror: null…}
But the Server Console don`t says 'NEW CONNECTION' why not? And how to fix it?