Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect_failed doesn't fire #375

Closed
giggsey opened this issue Jan 20, 2012 · 2 comments
Closed

connect_failed doesn't fire #375

giggsey opened this issue Jan 20, 2012 · 2 comments

Comments

@giggsey
Copy link

giggsey commented Jan 20, 2012

path = 'myurl.giggsey.com:port';

this.socket = io.connect(path, {
            'force new connection': true,
            'max reconnection attempts': 5,
            'connect timeout': 5000
        });

this.socket.on('connect_failed', function() {
            console.log('connect-failed');
        });

However, the connect_failed doesn't seem to appear.

I've tried with the latest released socket.io-client (0.8.7) also with the latest released socket.io (0.8.6).

I've seen an approved pull request which was related to this, and I'm pretty sure it's in the version I have.

@Ricket
Copy link

Ricket commented Mar 10, 2012

I am also not receiving a connect_failed event, calling io.connect with a nonsense path and the same options. Using the latest socket.io from NPM (version 0.9.0) with Chrome 17 in OSX.

Edit: just upgraded to version 0.9.1-1 via NPM, and added logging to ensure that this version is being used (which it is) - same result, no connect_failed event fired.

Edit2:

After digging around the source for a while, I happened upon the "error" event. It seems that in most cases when a connection fails, the error event is triggered instead of connect_failed. Looks like connect_failed is reserved for specific cases such as when the connection succeeds but the handshake fails, when an error packet is received with reason=='unauthorized', and perhaps others.

So the "solution" to this is to subscribe to the "error" event (as well as 'connect_failed'). In my app, I translate the error event into 'Error connecting to server', while connect_failed shows 'Connection failed; try refreshing the page'. I'm not yet sure if this is correct or even adequate, but until I get a chance to test these situations, I think it'll do.

@coredump
Copy link

I can confirm that getting a handler for the 'error' event solves at least part of this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants