Connect event not fired for namespaced sockets #255

Closed
sentientmatter opened this Issue Jul 27, 2011 · 10 comments

Comments

Projects
None yet
9 participants
@ghost

ghost commented Jul 27, 2011

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.

Contributor

3rd-Eden commented Jul 27, 2011

According to our unit test, it works just fine: https://github.com/LearnBoost/socket.io-client/blob/master/test/socket.test.js#L139-182
Are you running the latest version?
On Jul 27, 2011, at 4:07 AM, sentientmatter wrote:

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.

Reply to this email directly or view it on GitHub:
LearnBoost#255

@ghost

ghost commented Jul 28, 2011

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');
});

e6nian commented Aug 11, 2011

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.

josephg commented Aug 18, 2011

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

Contributor

3rd-Eden commented Aug 18, 2011

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?

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.

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

+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.

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 commented Apr 1, 2014

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.

@rauchg rauchg closed this Nov 25, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment