Socket.io-client: Can´t catch ERR_CONNECTION_REFUSED

Created on 14 Nov 2016  ·  8Comments  ·  Source: socketio/socket.io-client

  • [x] report a bug
  • [ ] request a feature

Current behaviour

I cant catch the "ERR_CONNECTION_REFUSED" error when the socket connection is killed.

I have the following Event-Listener in my Code:

           this.socket.on('error', (err) => {
                console.log('Error connecting to server', err);
            });

            this.socket.on('disconnect', () => {
                console.log('Disconnect from server');
            });

            this.socket.on('reconnect', (number) => {
                console.log('Reconnected to server', number);
            });

            this.socket.on('reconnect_attempt', () => {
                console.log('Reconnect Attempt');
            });

            this.socket.on('reconnecting', (number) => {
                console.log('Reconnecting to server', number);
            });

            this.socket.on('reconnect_error', (err) => {
                console.log('Reconnect Error', err);
            });

            this.socket.on('reconnect_failed', () => {
                console.log('Reconnect failed');
            });

            this.socket.on('connect_error', () => {
                console.log('connect_error');
            });

and got this Error on Chrome console:

socket connected
socket.io.service.ts:69 Disconnect from server
socket.io.service.ts:83 Reconnect Attempt
socket.io.service.ts:90 Reconnecting to server 1
zone.js:1382 GET https://XXX:3000/socket.io/?auth_token=XXX&EIO=3&transport=polling&t=LXY2NwI net::ERR_CONNECTION_REFUSEDscheduleTask @ zone.js:1382ZoneDelegate.scheduleTask @ ...
socket.io.service.ts:111 connect_error
socket.io.service.ts:97 Reconnect Error Error: xhr poll error(…)
socket.io.service.ts:83 Reconnect Attempt
socket.io.service.ts:90 Reconnecting to server 2
...

Steps to reproduce (if the current behaviour is a bug)

Start a working app and stop the socket-server.

Setup

  • OS: macOS Sierra & Linux Debian Jessie
  • browser: Chrome
  • socket.io version: 1.5.1

Most helpful comment

What if we haven't included script tag for socket.io.js? Then how to solve this error?
I have angular 2 application , i just pointed out my chat component to hit the server initially and throwing error if server script is not running.

so.

this.socket.on('connect_error', function (data) {
        console.log('connection_error');
    });

By the above statement i was able to catch the connection error when server isn't started. Kindly specify the section in which you've written the code.

All 8 comments

Hi!

I cant catch the "ERR_CONNECTION_REFUSED" error when the socket connection is killed.

I don't understand... Aren't the events 'reconnect_error' and 'connect_error' properly emitted?

I have the same issue. Have you found any solution to this bug?

I have the exact same issue

@xtremetom @bermanboris

May I ask what behaviour you are expecting?

Short: That error doesnt come from socket.io its a "No route to host" from chrome

I'm pretty sure you try to include the socket.io.js from your node-server, which isn't running.
Check your ) Handle an error with an onerror-attribute defined for this script tag. You wont get this error out of your console, when you dont check if the server is running, before including the script tag.

Closed due to inactivity, please reopen if needed.

What if we haven't included script tag for socket.io.js? Then how to solve this error?
I have angular 2 application , i just pointed out my chat component to hit the server initially and throwing error if server script is not running.

so.

this.socket.on('connect_error', function (data) {
        console.log('connection_error');
    });

By the above statement i was able to catch the connection error when server isn't started. Kindly specify the section in which you've written the code.

@kayzeeparacha This event catch the error however the error message is still displaying in console. I read in this post the message is not sending from socket.io and make sense. 😣

Was this page helpful?
0 / 5 - 0 ratings

Related issues

newpanjing picture newpanjing  ·  3Comments

Sairyss picture Sairyss  ·  4Comments

gtk2k picture gtk2k  ·  3Comments

catamphetamine picture catamphetamine  ·  3Comments

Tiboonn picture Tiboonn  ·  6Comments