我正在使用此节点库: https://github.com/jessereitsma/node-base
我正在使用websockets: https://github.com/einaros/ws
这是我在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'));
});
当我想要连接时,我打开控制台日志并输入:
new WebSocket('ws://dylan.jrnode.eu:8080');
输出:
WebSocket {binaryType:“blob”,extensions:“”,protocol:“”,onclose: null,onerror:null ...}
但是服务器控制台没有说“新连接”为什么不呢?以及如何解决它?
答案 0 :(得分:0)
哎呀,这是一个服务器问题,我无法访问端口8080.现在修复了。