带有SSL的node.js服务器socket.io-client

我尝试通过socket.io来设置两个node.js服务器之间的通信。 节点服务器使用SSL,但我不明白它运行。 我没有得到任何反馈,它接近这个:

Node.js socket.io-client connect_failed / connect_error事件

这是行不通的。 没有反应。

var clientio = require('socket.io-client'); console.log('Trying stuff ...'); // the channel does not exist var socket = clientio.connect( 'http://localhost:4000/news' ); // I expect this event to be triggered socket.on('connect_failed', function(){ console.log('Connection Failed'); }); socket.on('connect', function(){ console.log('Connected'); }); socket.on('disconnect', function () { console.log('Disconnected'); }); 

但如果我尝试:

 // Bind to the news namespace, also get the underlying socket var ns_news = clientio.connect( 'https://localhost:9000' ); var socket = ns_news.socket // Global events are bound against socket socket.on('connect_failed', function(){ console.log('Connection Failed'); }); socket.on('connect', function(){ console.log('Connected'); }); socket.on('disconnect', function () { console.log('Disconnected'); }); // Your events are bound against your namespace(s) ns_news.on('myevent', function() { // Custom event code here }); 

我可以看到,ns_news没有元素套接字,所以我得到:

 TypeError: Cannot call method 'on' of undefined 

那么如果连接成功与否,如何连接这两台服务器呢? 而我的下面的问题是:

这两台服务器怎么能相互authentication呢? 意思是:服务器A对服务器B说: – 嘿,给我那个秘密string服务器B检查服务器A的证书,如果没关系 – 这是string

我怎么做节点?