views:

30

answers:

2

Hello all,

I know that there are a variety of similarly posed questions here on SO and I've had a look at the ones that are suggested as matches. However, none quite manage to solve the issue that I'm facing. Basically, I'd like to know if there's a way to 'subscribe' to an event at client level in order to have a small portion of the page rendered from the controller. I know that I can use javascript setInterval() (in combination with jquery ajax) to 'poll' the controller action in order to determine if something 'new' should be renedered onto the page. However, I'm not a huge fan of polling, especially when client browsers can be left unattended and are uneccessarily polling for changes. Multiply that by the number of potential client machines that could be browsing the app and you get a feel for the scale of the issue with this approach. Now, in truth, this is EXACTLY the approach that I use to refresh certain page fragments on some ('read' - MANY!!) of my existing sites.

However, I'd like to know what the options are for subscribing in 'reverse' to events and having the controller 'know' about the client browser and any events that it is subscribed to and the controller then 'push' out the update to the client on a 'needs must' basis. Is this something that happens outside of the normal desktop events scenario?? is the idea even scaleable or is it just the same potential bottleneck in reverse of the method that I currently use.

Hopefully, some interesting approaches out there to this double edged sword.

+2  A: 

The server can not contact the client. The only other option besides polling is leaving an open connection between the client and server that the server can then stream info through. This is not less resource consuming than polling.

You can write a script that detects action on the client browser and goes into a "sleep" mode after a few idle minutes during which it does not poll.

Sruly
+1 actually, i like the idea of the 'sleep' mode. that may make sense of the notion in a more scalable way. i won't mark as answer 'yet' as i'm keen to see other suggestions but this kinda tackles my problem domain - i.e. the uneccessary polling.
jim
i'm currently looking at this http://paulirish.com/2009/jquery-idletimer-plugin/ as a way of detecting 'idle-time'. should be able to whip up something that works based on polling only if within the designated idle-time valid period
jim
+1  A: 

Never tried it, as it seems to me that maintaining a long-running connection is a good way to run out of worker threads1 - but Comet seems to be what you're looking for.

  1. Note that others have suggested ways around the thread per connection model.
Mark Brackett
+1 as well. yes, i've read about comet and html5 (websockets). maybe that's a potential way fwd if lower html versions were catered for as well..
jim
webSync (http://www.frozenmountain.com/websync/) looks exactly along the lines of what i was thinking about!! would love to see 'free/cheaper' alternatives to that mind you.
jim