1

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 #<Object> has no method 'connect'
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106
Erel Segal-Halevi
  • 33,955
  • 36
  • 114
  • 183

1 Answers1

4

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
});
Menztrual
  • 40,867
  • 12
  • 57
  • 70