与ssl socket.io不工作

我有一个简单的node.js代码为websocket服务器使用socket.io模块,我只是不能使它的工作。 服务器运行时没有错误,但是当试图从浏览器连接时,我得到了“SOCKET ERROR:{”isTrusted“:true}”错误(我没有使用自签名证书,而是经过testing并被浏览器信任的Symantec证书) 。
这是我的代码:

var fs = require( 'fs' ) ; var app = require('express')(); var https = require('https'); var server = https.createServer({ key: fs.readFileSync('cert.key'), cert: fs.readFileSync('cert.cer'), },app); server.listen(50100); var io = require('socket.io').listen(server,{pingTimeout: 7000, pingInterval: 10000}); io.sockets.on('connection',function (socket) { console.log('new connection'); }); 

在客户端,我使用标准的Java脚本“var WS = new WebSocket(wsUri);”和wsUri是“wss:// siteaddress:50100”。
我尝试了与“ws”节点模块的代码,它似乎工作正常,但“WS”模块并没有我需要的所有方法(除非我失去了一些东西 – 我需要能够发送消息到选定的套接字或所有套接字并从套接字连接的客户端发送一些信息)。
我已经尝试了所有的build议在node.js,socket.io与SSL,但没有一个为我工作。
尝试debugging通过DEBUG = *节点myapp – 这里我得到的日志:

 express:application set "x-powered-by" to true +0ms express:application set "etag" to 'weak' +7ms express:application set "etag fn" to [Function: wetag] +2ms express:application set "env" to 'development' +1ms express:application set "query parser" to 'extended' +0ms express:application set "query parser fn" to [Function: parseExtendedQueryString] +1ms express:application set "subdomain offset" to 2 +0ms express:application set "trust proxy" to false +1ms express:application set "trust proxy fn" to [Function: trustNone] +1ms express:application booting in development mode +2ms express:application set "view" to [Function: View] +1ms express:application set "views" to '/opt/bitnami/apache2/wm/node/views' +0ms express:application set "jsonp callback name" to 'callback' +1ms socket.io:server initializing namespace / +145ms socket.io-parser encoding packet {"type":0,"nsp":"/"} +1ms socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +1ms socket.io:server creating engine.io instance with opts {"pingTimeout":7000,"pingInterval":10000,"path":"/socket.io","initialPacket":["0"]} +0ms socket.io:server attaching client serving req handler +10ms 

客户端尝试连接到WebSocket时,日志中没有显示任何内容。
有人能指出我的方向吗?
谢谢。

       

网上收集的解决方案 "与ssl socket.io不工作"

服务器端:

 `var express = require('express'); var app = express(); var server = app.listen(8080); var io = require('socket.io').listen(server);` 

客户端:

 <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> var mySocket = io.connect('localhost:8080', {transports: ['websocket'], reconnection: false,secure:false}); mySocket.on('connect', function () { mySocket.sendBuffer=[] console.log('Connected!'); }); 

如果您的浏览器connected失败,意味着连接已build立

尝试添加运输和来源与相应的端口

var io = require('socket.io').listen(server ....)

添加这个:

io.set('transports', ['websocket']); io.set('origins', 'YOUR_ORIGIN:*');

检查你的规则是否正确设置在Apache或Nginx,以便你有WSS。