8

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?

Ionică Bizău
114k95 gold badges311 silver badges488 bronze badges
asked Oct 29, 2013 at 20:15

2 Answers 2

20

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!

answered Nov 3, 2013 at 17:58
5
  • 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/2728686 Commented 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 Commented Mar 18, 2014 at 12:52
  • @AmpT even your website calm is showing xhr-polling in my browser Commented May 7, 2014 at 10:48
  • 2
    For use with simpleWebRTC I had to explicitly set port number 80 in url like so: http://myserver.herokuapp.com:80 Commented 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. Commented Dec 27, 2014 at 21:56
0

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

Fedor
23.6k42 gold badges59 silver badges179 bronze badges
answered Apr 16, 2024 at 4:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.