Can I set up socket.io chat on heroku?

前端 未结 7 562
栀梦
栀梦 2021-02-01 16:46

I have a simple socket.io chat application which I\'ve uploaded to one of the new Heroku \'cedar\' stacks.

Now I almost have everything working but I\'ve hit one stumbli

相关标签:
7条回答
  • 2021-02-01 16:54

    I was also having this problem on heroku. I was able to make it work using the hostname "myapp.herokuapp.com" (or simply window.location.hostname, to work both local and in production) and setting the port to 80. I'm using SocketIO 0.6.0.

    0 讨论(0)
  • 2021-02-01 16:59

    This has now changed as of Oct 2013, heroku have added websocket support:

    https://devcenter.heroku.com/articles/node-websockets

    Use:

    heroku labs:enable websockets
    

    To enable websockets and dont forget to remove:

    io.configure(function () { 
      io.set("transports", ["xhr-polling"]); 
      io.set("polling duration", 10); 
    }); 
    
    0 讨论(0)
  • 2021-02-01 16:59

    2011-06-25T21:41:31+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET appxxxx.herokuapp.com/socket.io/1/websocket/4fd434d5caad5028b1af690599f4ca8e dyno=web.1 queue= wait= service= status=503 bytes=

    Does this maybe mean the heroku router infront of the app is not configured to handle web socket traffic?

    [update] It would appear as of 6/22/2011 the answer is yes... heroku does not support socket.io see this post: http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/

    0 讨论(0)
  • 2021-02-01 17:00

    After trying every combination under the sun I finally just left it blank. Lo and behold that works perfectly. You don't even need the port.

    socket = new io.Socket();
    
    0 讨论(0)
  • 2021-02-01 17:05

    The correct way according the article on heroku is:

    io.configure(function () { 
      io.set("transports", ["xhr-polling"]); 
      io.set("polling duration", 10); 
    });
    socket = new io.Socket();
    

    This ensures that io.Socket won't try to use WebSockets.

    0 讨论(0)
  • 2021-02-01 17:07

    Wouldn't you just put your actual hostname?

    0 讨论(0)
提交回复
热议问题