Reputation: 203
I am using simple socket.io client module to connect to web socket but the connection is failing. The way I have learned is that right after you define socket, you can access connected property to find out the status of connection and it always return false. I am trying to connect to web socket in a child process on the same server where my main process is running.
var socket = require('socket.io-client')("ws://xx.xx.xxx.xxx");
console.log(socket.connected);
Upvotes: 0
Views: 273
Reputation: 203231
SocketIO connections should be initiated over HTTP(S):
var socket = require('socket.io-client')('http://localhost:6001');
(instead of ws://...
)
Then wait for the connect
event; when that fires, the client is connected to the server;
socket.on('connect', function() {
console.log('connected to server!');
...
});
Upvotes: 3