0

This may be a naive question but I was planning to create a new channel just before the existing channel timed out to make sure that my client was never without a channel. I thought I was being pretty clever until I read this caveat in the google channel api docs:

One Client Per Channel Per Page

A client can only connect to one channel per page. If an application needs to send multiple types of data to a client, aggregate it on the server side and send it to appropriate handlers in the client’s socket.onmessage callback.

I'm new to this, but it's not obvious to me how the channel unique identifies the page to which it is connected. Is there something in the javascript for channel.open() call that identifies the page it is being called in?

Thanks.

Community
  • 1
  • 1
Charlie Burns
  • 6,994
  • 20
  • 29

1 Answers1

3

The channel javascript creates a hidden iframe with a given id (on production). The communications takes place within the iframe. The javascript code will always access that iframe (and hence channel).

When you close the socket and channel, the hidden iframe will be destroyed. Afterwards you can create a new channe for the page.

dragonx
  • 14,963
  • 27
  • 44
  • I did not know that. Now I do. +1. Is this documented? How the iframe is created/destroyed? – rGil Jul 13 '13 at 07:02
  • 1
    Nope, the documentation gives almost no details on how the javascript works. This was learned from hacking at it and losing messages when I forgot to close a socket before attempting to open another. See these: http://eatdev.tumblr.com/post/13300565266/hacking-to-google-app-engine-channel-api http://eatdev.tumblr.com/post/13303910965/unhacking-the-google-app-engine-channel-api – dragonx Jul 13 '13 at 16:31