无法使用SSL连接到Socket IO

时间:2013-12-23 23:26:51

标签: node.js socket.io

服务器:

// Load libraries
var https = require('https');
var fs = require('fs');
var socketio = require('socket.io');

// The server options
var srvAddress = '123.123.123.123';
var srvPort = 8888;
var srvOptions = {
    key: fs.readFileSync('ssl/cert.key'),
    cert: fs.readFileSync('ssl/cert.crt'),
    ca: fs.readFileSync('ssl/cert-ca.crt')
};

// Create a Basic server and response
var app = https.createServer(srvOptions, function(req, res) {
    res.writeHead(200);
    res.end('Online...');
});

// Create the Socket.io Server over the HTTPS Server
var io = socketio.listen(app, srvAddress);

// Now listen in the specified Port
app.listen(srvPort, srvAddress);

客户端:

var socket = require("socket.io-client").connect('https://123.123.123.123:8888', {secure: true});

但客户端无法连接到服务器。我试过http而不是https,但结果相同。
服务器工作正常。没有ssl证书连接工作。当尝试通过网络打开时,一切也都有效。

0 个答案:

没有答案