2

I try to setup two node.js servers communication with each other over socket.io. The node servers use SSL, but I don't get it running. I do not get any feedback, its close to this:

Node.js socket.io-client connect_failed / connect_error event

This will not work. No response.

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');
});

but if I try:

// 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
});

I can see that ns_news has no element socket, so I get:

TypeError: Cannot call method 'on' of undefined

So how do I connect these two servers with feedback if the connection is successful or not? And my following question would be:

How can these two servers authenticate to each other? Means: Server A says to server B: - hey, gimme that secret string And Server B checks the certificate of server A and if it's ok - here's the string

How do I do it with node?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.