Note that there are some explanatory texts on larger screens.

plurals
  1. POChannel API closes a channel
    text
    copied!<p>First off, thank you @Moishe for the very useful API. I'm having a little timeout problem, maybe someone knows the answer. Here's how I open the channel:</p> <pre><code>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); // do stuff }; socket.onerror = function (error) { alert(error); }; socket.onclose = openChannel; }; openChannel(); </code></pre> <p>This works fine, I post my messages and they go to the other clients pretty quickly. But if I stay on the page for roughly 15 minutes, the server loses track of my channel. In dev, it throws an error (which I saw was a known bug: <a href="http://www.mail-archive.com/google-appengine@googlegroups.com/msg44609.html" rel="nofollow">http://www.mail-archive.com/google-appengine@googlegroups.com/msg44609.html</a>). But in prod, it still ignores messages on that channel after about 15 minutes.</p> <p>We fixed it by adding a <code>setInterval(getSomeUrl, everyMinute)</code> to the page, but we'd rather not have to do that. I noticed in Moishe's last commit for the trivia game sample that he took out a keep-alive. I didn't understand how he replaced it, and what he meant by onopen is reliable:</p> <p><a href="http://code.google.com/p/trivia-quiz/source/browse/trunk/src/index.html" rel="nofollow">http://code.google.com/p/trivia-quiz/source/browse/trunk/src/index.html</a></p> <p><em>Update</em>: Server side code is</p> <pre><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) # TODO: Replace this line and the next with a query self.model['messages'] = sorted(self.model['messages'], key=lambda m: m.timestamp, reverse=True) self.writeTemplate('index.html') </code></pre> <p><code>BaseHandler</code> is just a base class I use for all my GAE handlers, it provides <code>checkUser</code> which redirects if the user isn't logged in, and it provides <code>writeTemplate</code> which takes what's in <code>self.model</code> and writes it in a template. It's just a proof of concept, so no cache or anything else other than what's above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload