AngularJS:通过https与socket.io聊天
我正在运行这个示例聊天应用程序https://github.com/btford/angular-socket-io-im使用socket.io/angular/node来做一个基本的即时通讯客户端。
但是,当我尝试通过https工作时遇到麻烦。
没有套接字事件在服务器上被捕获,所以没有聊天消息被发送到客户端,并且用户不能join房间。 我也在socket.io.js
的客户端上得到这个错误:
Uncaught TypeError: Cannot call method 'onClose' of null
我创build了一个在端口8000
上侦听的express
https
服务器,并将套接字定义修改为:
var socket = io.connect('https://localhost:8000',{secure: true, port:8000});
在js/services.js
和/bower_components/angular-socket-io/socket.js
不太清楚如何去解决这个问题。 提前致谢!
我有一个应用程序,这完全一样的东西:)使用套接字io和使用:8080您将需要确保您的安全证书注册,同时https://localhost
和https://localhost:8000
已添加到你的钥匙串,否则页面将加载,但你的套接字连接将失败。
只需要做一些修改就可以通过https访问,尽pipe这是一个旧的express 2.5应用程序,您应该考虑一下: https : //github.com/guille/chat-example.git
/** * Module dependencies. */ var fs = require('fs'); var options = { key:fs.readFileSync('key.pem'), cert:fs.readFileSync('cert.pem') }; var express = require('express'), routes = require('./routes'), socket = require('./routes/socket.js'); var app = module.exports = express.createServer(options); // Hook Socket.io into Express var io = require('socket.io').listen(app); // Configuration app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.set('view options', { layout: false }); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.static(__dirname + '/public')); app.use(app.router); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); // Routes app.get('/', routes.index); app.get('/partials/:name', routes.partials); // redirect all others to the index (HTML5 history) app.get('*', routes.index); // Socket.io Communication io.sockets.on('connection', socket); // Start server app.listen(8080, function(){ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); });