node.js - How do I trigger a real time client update in Rails -


i'm creating online multiplayer board game using rails, , want game able played without having manually refresh page. i'm planning on using websockets or server sent events's update page. haven't decided yet, don't expect make difference question.

the thing i'm confused knowing when send update client. example, let's making chess, , player1 took turn. send move server, server save database. how player2's websocket or sse know push info player1's move player2's brower?

i know regularly query database see if game has been updated, seems hard scale since every user querying database often.

is there easy way wait update database , notified of automatically somehow? or there other solutions?

i've looked around online bunch solutions this, haven't gotten concrete ideas. i'm open using library or whatever solve problem long it's free. i've seen paid solutions aren't option.

i saw suggest somehow using node.js alongside rails realtime. don't know node.js, have heard it's asynchronous functionality that. i'd interested in learning how use if it's better rails solution.

i'm using rails 3.2, if rails 4 has work here, i'd interested in well.

as nik suggested, use faye ruby server if you're ruby developer.

in terms of how things hang together:

  1. each game channel
  2. each player subscribes channel
  3. when player makes move, move sent server
  4. the server saves move against game in db
  5. the server sends message channel.
  6. both player's ui update new move.

this setup allows replay whole game or continue left off. moves db , send them in order new channel. might not performant, should work.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -