Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SocketIO when server is down the clientside gives a window alert of undefined?

SocketIO when server is down the clientside gives a window alert of undefined?

Problem

When i execute and start my Server file e.g.

 node app.js

and then i force stop the server by exiting the node console or CTRL-C how come i get a window Alert of UNDEFINED

e.g.

window.alert(undefined);

i know for a fact its not coming from my code so it must be coming from the Socketio package but if so can i errorHandle this? and instead of alert undefined it could alert the user that the server is down or cannot be reached?

Thanks

Aiden

Problem courtesy of: Aiden

Solution

check https://github.com/LearnBoost/socket.io/wiki/Exposed-events

Client events (not all)

  • socket.on('disconnect', function () {}) - "disconnect" is emitted when the socket disconnected

  • socket.on('connect_failed', function () {}) - "connect_failed" is emitted when socket.io fails to establish a connection to the server and has no more transports to fallback to.

  • socket.on('error', function () {}) - "error" is emitted when an error occurs and it cannot be handled by the other event types.

Looks like in some place of your code (client) you have a alert(socket); or something like this.

check the client socketio file too.

Solution courtesy of: jmingov

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

SocketIO when server is down the clientside gives a window alert of undefined?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×