Realtime websocket-like behavior possible on Heroku?

a 夏天 提交于 2020-01-06 12:36:52

问题


I am considering making a chess app in Rails where moves need to be pushed from the server to the client browser asynchronously (ideally with websockets).

However, from what little research I've done it appears that Heroku does not support websockets. But there is an alternative in using socket.io configured to use long polling instead of websockets.

Is long polling insufficient to achieve latency requirements for something like a 5 minute blitz game of chess?


回答1:


The Heroku Cedar stack supports HTTP Streaming and Long Polling: https://devcenter.heroku.com/articles/request-timeout#longpolling_and_streaming_responses

It doesn't support WebSockets. But you can use a framework like Faye and use XHR as the transport mechanism. It seems there's a project for this. See: Is it possible to host FAYE, on Heroku?

If you want to use WebSocket in your game client and have your backend on Heroku then the only solution that I know of right now is to use the Pusher (who I work for addon): https://addons.heroku.com/pusher




回答2:


An alternative that's much closer to Websockets is Server Sent Events. It's one-way from server to client (you can just keep making standard requests for the client->server direction).

Heroku does appear to support Server Sent Events, as do most browsers that support Websockets (IE10 being the exception that doesn't).



来源:https://stackoverflow.com/questions/14908212/realtime-websocket-like-behavior-possible-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!