Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Connect event not fired for namespaced sockets #255

Closed
sentientmatter opened this Issue · 10 comments

9 participants

Sentient Matter Arnout Kazemier Sean Yu Joseph Gentle David Martin Valerio Coltrè Justin Pincar gogaman7 Guillermo Rauch
Sentient Matter

When setting up namespaced sockets, the connect event doesn't seem to be firing. This may only be occuring on ports other than 80 (I'm not able to test websockets on port 80).

This code works as expected and the callback fires:

var socket = io.connect('http://example.com:8124');
socket.on('connect', function () {
    //Works just fine
    console.log('connected');
});

But when the namespace is added, the callback never fires:

var socket = io.connect('http://example.com:8124/things');
socket.on('connect', function () {
    //Never gets here
    console.log('connected');
});

Again I suspect this occurs when the port and namespace are specified, but I haven't been able to test that theory.

Arnout Kazemier
Sentient Matter

Yep latest version, 0.7.4 client and 0.7.7 server. I tested on port 80 just now and still nothing...the connect event isn't fired if connecting with a namespace, tested on Firefox 5 using long polling and Chrome using websockets. I also noticed that my server side .on('connection') isn't being fired either, am I just missing something? Here is code I'm using:

Client:

var stuff = io.connect('http://mydomain.com:8124/stuff');
stuff.on('connect', function () {
    // socket connected (never gets fired)
    console.log('connected');
});

stuff.on('hello', function(){
    //Never gets here either
    console.log('got hello');
});

And Server:

var io = require('socket.io'),
express = require('express');

var app = express.createServer(), io = io.listen(app);

app.listen(8124);

io.of('/stuff').on('connection', function(socket){
    //Never gets fired
    console.log('user connected');

    socket.emit('hello');
});
Sean Yu

yep. still not working here.
latest version, 0.7.4 client and 0.7.8 server

I think the unit test use disconnect,but our scope maybe much more complex,our network interrupted or else.
(for me, I transfer a lot of data by socket.io, every 2.5 min or less , the server log said "transport end, then clear the timeout ... or else ,reconnection come." )

And I found that, when the reconnection called, the clients get a new ID.

Joseph Gentle

Could it be simply that subsequent connections to the same host don't fire a 'connection' event?

Arnout Kazemier

They connection event is only fired if the client sends a connect packet to the server.

I suspect that

var socket = io.connect('http://example.com:8124/things');
socket.of('/namespace').on('connect', function () {
    //Never gets here
    console.log('connected');
});

does work?

David Martin

I have version 0.9.6 of the client installed. The following still does not work for me:

var socket = io.connect('/index', { port: 6373 });
socket.on('connect', function () {
    // Never gets here
});

However, if I connect to the default namespace first, and then connect to /index, it works:

var socket1 = io.connect('', { port: 6373 });
socket1.on('connect', function () {
    // We get here
    var socket2 = io.connect('/index', { port: 6373 });
    socket2.on('connect', function () {
        // We also get here
    });
});

Hopefully that narrows this down somehow.

Valerio Coltrè

socket.io client still haves this issue @ version 0.9.16 ...

Justin Pincar

+1, this is a big issue for me as well. It seems as though if I only pass a url to connect() things fire off correctly, but adding the options object causes issues.

Justin Pincar

The following fires events:
App.socket = io.connect('', {secure: true, resource: "3001/socket.io"});

The following doesn't fire events:
App.socket = io.connect('https://www.bitsaloon.com/3001/', {secure: true, resource: "3001/socket.io"});

Do I have the first parameter incorrect? What exactly am I supposed to pass in?

gogaman7

The following did a trick for me with: socket.io-client: "^0.9.16"

io.connect("http:///localhost:4000", {'force new connection': true});

Now 'connect' event fires consistently and there is no re-use.

I figured out this option by examining socket.io-client/lib/io.js line: 192
Since I can't even find this io.js file in github, I think there is refactoring in future releases, and this option might not work.

At least this might be helpful to somebody who will take this temporary work around.

Guillermo Rauch rauchg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.