0
votes

I've been attempting to get socket.io-client to work with a socket.io localhost server on the port 9000. Both the client and server are based in NodeJS.

This seems to connect to the server:

io = require('socket.io-client')

socket = io.connect('http://localhost:9000', {resource : 'node_modules/socket.io'})

socket.on 'connect', ->
    socket.emit 'message', {hello: 'world'}
    return

However it gives the following error:

      self.transport.onClose();
                 ^
TypeError: Cannot call method 'onClose' of null

The server appears to register the request properly:

GET /node_modules/socket.io/1/?t=1388048751499 200 11ms - 2.81kb

Is there a working example of a NodeJS-based client for Socket IO? Links found:

Uncaught TypeError: Cannot call method 'onClose' of null

1
Where is self.transport.onClose(); called?mekwall
I believe that is from the socket.io-client module.. It seems to be a pretty stable module. Not quite sure why it's not working. I checked the documentation for the constructor, it seems to be not working as well, had to google for that too lol..jhtong
Alternatively, is there a better way / another module that should be checked out?jhtong
This is not a problem with either socket.io or socket.io-client. Your are most definately doing something wrong. We need more code to be able to figure out what isn't working properly.mekwall

1 Answers

2
votes

What. lol. The module on NPM is broken. -.-

Guys do a direct pull from Github -.- This works.

npm install git+https://github.com/LearnBoost/socket.io-client.git

In v1.0, this worked for me (together with the pong example below)

Server

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
io.on('connection', function(){ // … });
server.listen(3000);

Express running on dev port (for me, 9000), Socket.io running @ port 3000

Ref: http://liamkaufman.com/blog/2012/01/28/testing-socketio-with-mocha-should-and-socketio-client/#trouble-shooting