2

Problem description: channel messages no returned to ajax script. Initially, messages are delivered to clietn side, but the problem appears when I set larger timeout in js:

goog.appengine.Socket.POLLING_TIMEOUT_MS = 5000; //poll every 5 seconds

I've added a very basic Python code to test if Channel API works in my Google App Engine app.

index:
token = channel.create_channel(CHANNEL_NAME)
channel.send_message(CHANNEL_NAME, message)
#token is passed to template

additional_view:
#is another view, trigger manually from browser after index
from django.utils import simplejson
channel.send_message(CHANNEL_NAME, simplejson.dumps(data))

At client side I have a regular js with onMessage code.

The problem is that no messages are returned to client-side requests. They all come empty to polling ajax (as seen in Firebug). In application log I can see that channel is created:

"Creating channel token channel-2382918168-broadcast with client id broadcast" and later message is sent but with a comment:

in between come these requests:

INFO     2011-08-03 14:33:32,000 dev_appserver.py:4248] "POST /_ah/channel/connected/ HTTP/1.1" 404 -
INFO     2011-08-03 14:33:33,780 dev_appserver.py:4248] "POST /_ah/channel/disconnected/ HTTP/1.1" 404 -

** ....message text...to channel with key (broadcast): no clients connected***

How does channel/message function at deeper level? Are messages lost if no clients are connected or they are retrived by newly connect clients? If for some reason I create a channel with the same name, would it distroy undelivered messages it has inside?

AlexA
  • 4,028
  • 8
  • 51
  • 84
  • What browsers have you tried adjusting the timeout in? Have you tried smaller values? As I recall I've seen this happen in some browsers when using a polling delay 3 seconds or greater. – Robert Kluin Aug 03 '11 at 16:16
  • I tried FireFox 3.6. Smaller values work. Just wanted to makes less ajax requests, but I guess that is somehow against Channel API rules. – AlexA Aug 03 '11 at 20:04

1 Answers1

6

Stay away from setting the POLLING_TIMEOUT_MS higher than 1.5 sec, the dev_appserver will assume you have disconnected.

It does not work via polling in production, so you do not have to worry about the timeout really.

Edit: just saw Robert's comment; personally I have even had issues if I set the polling to 3sec in Chrome/Safari/Firefox. I now just have ?disable_channel=true query strings on my apps so that I can run them without setting my laptop on fire with the CPU usage.

Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57
  • 1
    well techincally it *is* polling... but it's [long polling](http://en.wikipedia.org/wiki/Push_technology#Long_polling), so a timeout between requests doesn't really apply as the connection is kept open until data arrives. This is not possible with the dev-server due to it being single-threaded and so only able to serve one request at a time. – Chris Farmiloe Aug 03 '11 at 20:34
  • 1
    I often use 1 or 2 second delays without issues. I also like the idea of just making a disable_channel for when you're not testing working on those features of an app. – Robert Kluin Aug 03 '11 at 20:45