server-side connection to a socket.io server
Problem
I have a Java Server that connects with web-browsers through web-sockets, specifically socket.io, specifically this implementation: https://github.com/mrniko/netty-socketio
Now I would like to connect to the same server, not from a web-browser (through Javascript), but from a Node.JS program.
The problem is, in all examples that I found, the Node.JS program is the server, and the clients are always web-browsers.
I tried to use a code similar to the client connection code in node.js:
var io = require('socket.io');
var socket = io.connect("http://localhost:9080");
but got this error:
TypeError: Object #
Solution
You need to use socketio-client
$ npm install socket.io-client
https://github.com/LearnBoost/socket.io-client
You can then connect to another socket server by the following:
var io = require('socket.io-client');
var socket = io.connect('http://domain.com');
socket.on('connect', function () {
// socket connected
});
Discussion
View additional discussion.