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?
2 Answers 2
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!
-
I also found this answer, which also provides more clarity on how XHR polling could just randomly be activated, when randomly saved to cookies: stackoverflow.com/a/19680457/2728686AmpT– AmpT11/03/2013 18:09:11Commented Nov 3, 2013 at 18:09
-
1"I then restarted my server by pushing to heroku and having it rebuild." You can restart by doing
heroku restart
gberger– gberger03/18/2014 12:52:52Commented Mar 18, 2014 at 12:52 -
@AmpT even your website
calm
is showing xhr-polling in my browserAshish Negi– Ashish Negi05/07/2014 10:48:45Commented May 7, 2014 at 10:48 -
2For use with simpleWebRTC I had to explicitly set port number 80 in url like so:
http://myserver.herokuapp.com:80
jmarceli– jmarceli05/20/2014 12:23:34Commented May 20, 2014 at 12:23 -
5"heroku labs:enable" was a good answer at the time, but it no longer works, nor is it necessary, since websockets is no longer a lab feature on Heroku, but is enabled by default.user1147171– user114717112/27/2014 21:56:23Commented Dec 27, 2014 at 21:56
you must use
WebSocket connection to wss://<myherokuapp>.herokuapp.com/socket.io/1/websocket/HBWE2BFvHahlSWk5ppHP
wss://
not ws://
because Heroku is run on https protocol