Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket not working with socket.io in heroku

My app is working fine in localhost with socket.io using websockets and xhr-polling and it's working with xhr-polling in heroku, but since heroku provided support for websocket I can´t make it work using websockets.

My Chrome console shows this message:

WebSocket connection to 'ws://<myherokuapp>.herokuapp.com/socket.io/1/websocket/HBWE2BFvHahlSWk5ppHP' failed: Unexpected response code: 503

I already enabled websocket labs.

Is there any working example of websocket using socket.io?

like image 925
Igor Avatar asked Oct 29 '13 20:10

Igor


People also ask

Can you use WebSockets with Heroku?

The normal Heroku HTTP routing timeout rules apply to WebSocket connections. Either client or server can prevent the connection from idling by sending an occasional ping packet over the connection.

Does socket.io work on Heroku?

Socket.io + NodeJS doesn't work on Heroku.

Is socket.io and WebSocket same?

It provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback. WebSocket is the technology, while Socket.io is a library for WebSockets.


1 Answers

I had the same problem and just fixed it by reactivating the websockets on my app on heroku. It had just randomly switched over to XHR polling for some reason.

I used this command from heroku's site (@ https://devcenter.heroku.com/articles/heroku-labs-websockets) to reactivate it:

heroku labs:enable websockets -a myapp

I then restarted my server by pushing to heroku and having it rebuild (or using: heroku restart).

I also have a working copy of a very basic socket.io chat application (written by Smitha Milli) running at: http://calm-gorge-8474.herokuapp.com/ that you can test.

Hope this helps!

like image 171
AmpT Avatar answered Oct 01 '22 17:10

AmpT