First of all, thanks @Moishe for the very useful API. I have a little problem with the timeout, maybe someone knows the answer. This is how I open the channel:
var openChannel = function () { var channel = new goog.appengine.Channel($('#token').val()); var socket = channel.open(); socket.onopen = function () {}; socket.onmessage = function (m) { var message = JSON.parse(m.data);
This works great, I post my messages and they go to other clients pretty quickly. But if I stay on the page for about 15 minutes, the server loses its channel. In dev, it throws an error (which I saw was a known error: http://www.mail-archive.com/ google-appengine@googlegroups.com /msg44609.html ). But in prod, it still ignores messages on this channel after about 15 minutes.
We fixed it by adding setInterval(getSomeUrl, everyMinute) to the page, but we should not do this. I noticed in Moishe the last fix for the trial trivia game that he pulled out alive. I did not understand how he replaced it, and what he meant by onopen is reliable:
http://code.google.com/p/trivia-quiz/source/browse/trunk/src/index.html
Update: server side code
class Home(BaseHandler): def get(self): self.checkUser() if self.user: userId = self.user.user_id() token = channel.create_channel(userId) chatClients[userId] = token self.model['token'] = token players = self.checkChatRoom() self.model['users'] = players self.model['messages'] = map(lambda k:db.get(k), self.chat_room.messages)
BaseHandler is just the base class that I use for all my GAE handlers, it provides a checkUser that redirects if the user is not logged in, and it provides a writeTemplate that accepts what is in self.model and writes it in the template . This is just a proof of concept, so there is no cache or anything else besides what is stated above.
source share