我使用这个节点基础: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'));
});
当我想连接时,我打开控制台日志并输入:
新WebSocket (ws://dylan.jrnode.eu: 8080);
输出:WebSocket {binaryType: "blob",扩展:",协议:",onclose:Null, onerror: Null}
但是服务器控制台没有显示'NEW CONNECTION',为什么不呢?如何解决这个问题?
哎呀,这是服务器问题,我无法访问端口8080。