h1

GAE + GWT 006 – Channels pt. II

June 13, 2011

So after some minor tweaks using channels, my Collaba-Doodle is now much more responsive and works in a manner which seems more real-time than the previously trialled polling approach. Yay for channels.

However, my efforts were not completely faultless… Because of the way I structured things (all my demo modules on a single page) and the way channels work (only one channel per page), I clearly needed to either

  1. Put the demos on separate pages; or,
  2. Have the channel at the top ‘live demo’ page and filter to the relevant module.

I didn’t quite want to have each demo on a separate page, so I opted for option 2. Thus, my Shoutbox and Collaba-Doodle share the same channel token. However, the message which is sent is encoded and interpreted differently based on the ‘msgType’ of the message.

I also set up a basic ChannelListener which can register listeners based on the msgType and then act upon that data. A simple solution which works for now but there’s definately a trade off with this approach

  1. We either have to parse the message multiple times in each module and accept or ignore the message; or,
  2. Out top level ‘live demo’ page knows exactly about each of its children and what msgType message they expect.

Given my LiveDemo is still quite small, opting for the first option seemed again, the easiest option and required the least amount of work in order to test the power of channels.

Finally I’ve been wondering how to close connections to remove the clientID from our table and it seems windowCloseEvent() solved my problems – called when the user navigates away from the page or the window is closed, we thus send a last message to the server telling it to close the socket and remove the clientID.

And thus the circle is complete – create a socket > send message > recieve updates > close socket. Cool. What next??

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.