Updating Page Content in (almost) Realtime

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Updating Page Content in (almost) Realtime

Post by Spectre557 on Fri Apr 22, 2011 10:42 am
([msg=56602]see Updating Page Content in (almost) Realtime[/msg])

I'm currently working on my first multi-user (and browser-based) application, a basic quiz-based game, using ColdFusion 9. I'll be storing player-specific (e.g. score) and game-session-wide (e.g. question number) variables in a database on the server. The problem I'm struggling with right now is how to reflect changes in data on the server side dynamically within the clients' browsers.

The simplest example of this is the pre-game lobby, where a list of connected players is displayed with their respective 'ready statuses' (green/red light, or just text for now). When all 4 player slots are filled by connected players and all players are ready, a round begins.

I originally looked at stuff like socket programming, which I found to be far too complicated for my purposes, and I've had a brief look at using Comet, although I haven't been able to find any good tutorials or guides so exactly what implementation to use and how I would go about it remains a mystery to me.

Essentially I just want it so that whenever I make a change to the database, all clients get updated to reflect the new data, in the simplest way possible.
Last edited by Spectre557 on Wed Apr 27, 2011 12:01 pm, edited 1 time in total.
Current obsession: Minecraft
User avatar
Spectre557
Poster
Poster
 
Posts: 215
Joined: Wed Apr 29, 2009 4:04 am
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by Goatboy on Fri Apr 22, 2011 2:24 pm
([msg=56605]see Re: Updating Page Content in (almost) Realtime[/msg])

Since HTTP is connectionless, a few techniques have been devised to create a semblance of a maintained connection. I don't have a ton of time to write the response I'd like, but two things to look into are long polling and pushlets.

http://en.wikipedia.org/wiki/Push_technology

If timing is not absolutely critical, I'd use a polling method, perhaps sending a poll every .5 seconds.
Mundus Vult Decipi
User avatar
Goatboy
Expert
Expert
 
Posts: 2443
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by fashizzlepop on Fri Apr 22, 2011 2:35 pm
([msg=56610]see Re: Updating Page Content in (almost) Realtime[/msg])

Ajax and JavaScript.

'Nuff Said.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Moderator
Moderator
 
Posts: 2147
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by thetan on Fri Apr 22, 2011 9:47 pm
([msg=56621]see Re: Updating Page Content in (almost) Realtime[/msg])

client side WebSockets ( http://socket.io/ ) and asynchronous server side communication over the web socket ( http://nodejs.org/ )

I built a real time monitoring system using socket.io and node.js for monitoring my re-architecture of the inventory control system i built at work. Shit's boss.
"If art interprets our dreams, the computer executes them in the guise of programs!" - SICP

Image

“If at first, the idea is not absurd, then there is no hope for it” - Albert Einstein
User avatar
thetan
Contributor
Contributor
 
Posts: 653
Joined: Thu Dec 17, 2009 6:58 pm
Location: Various Bay Area Cities, California
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by tgoe on Wed Apr 27, 2011 9:09 am
([msg=56712]see Re: Updating Page Content in (almost) Realtime[/msg])

Here's another option I've been playing with recently -> Channel API
User avatar
tgoe
Contributor
Contributor
 
Posts: 527
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by Spectre557 on Wed Apr 27, 2011 1:07 pm
([msg=56717]see Re: Updating Page Content in (almost) Realtime[/msg])

fashizzlepop wrote:Ajax and JavaScript.

The ability to update parts of the page without a refresh using AJAX is useful to me, but from what I understand it has to be initiated from the client side - I need to be able to update a page without the user doing or clicking on anything (triggered by another user).

thetan wrote:client side WebSockets ( http://socket.io/ ) and asynchronous server side communication over the web socket ( http://nodejs.org/ )

I actually looked into websockets briefly after someone suggested using HTML5, and it seemed like a good solution. However, it looks like due to a vulnerability this feature won't be supported for the time being by most browsers (http://en.wikipedia.org/wiki/WebSockets#Browser_support)

tgoe wrote:Here's another option I've been playing with recently -> Channel API

I'd never heard of this before, or even had a proper look at the Google App Engine. Very interesting, and I wish I'd known about this before. But, although this solution seems perfect for what I want to do, it looks like I would have to write the thing in Java/Python (neither of which I'm comfortable coding in yet).

Goatboy wrote:Since HTTP is connectionless, a few techniques have been devised to create a semblance of a maintained connection. I don't have a ton of time to write the response I'd like, but two things to look into are long polling and pushlets.

http://en.wikipedia.org/wiki/Push_technology

If timing is not absolutely critical, I'd use a polling method, perhaps sending a poll every .5 seconds.

I had a brief look at pushlets, and to be honest I'm not sure I understand it (yet).

I would love nothing more than to play around with these different methods... The only problem is time, or rather a lack of it. I'm getting close to a deadline for this, and the basic framework is already partly built, so I can't re-do the whole project or learn a new (non-ridiculously-simple) method.

Although it's not the most elegant way, it looks like I'll stick to some kind of long-polling and AJAX.

Thanks for the info guys, much appreciated.
Current obsession: Minecraft
User avatar
Spectre557
Poster
Poster
 
Posts: 215
Joined: Wed Apr 29, 2009 4:04 am
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by thetan on Thu Apr 28, 2011 10:42 am
([msg=56736]see Re: Updating Page Content in (almost) Realtime[/msg])

obviously you didn't read into socket.io

socket.io just makes real time communication happen regardless on what your browser supports or not :)
"If art interprets our dreams, the computer executes them in the guise of programs!" - SICP

Image

“If at first, the idea is not absurd, then there is no hope for it” - Albert Einstein
User avatar
thetan
Contributor
Contributor
 
Posts: 653
Joined: Thu Dec 17, 2009 6:58 pm
Location: Various Bay Area Cities, California
Blog: View Blog (0)


Re: Updating Page Content in (almost) Realtime

Post by fashizzlepop on Fri Apr 29, 2011 8:24 pm
([msg=56786]see Re: Updating Page Content in (almost) Realtime[/msg])

Also, Ajax and JavaScript can do whatever the hell it wants regardless of the user's wishes... most of the time.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Moderator
Moderator
 
Posts: 2147
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests