2
votes

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?

1
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
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

1 Answers

6
votes

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.