At Google IO 2010, the app engine team announced that they had a Channel API in the works. This week I got invited by Moishe Lettvin of the Channel API team to join a handful of developers to try it out. The api is undocumented at the moment and can be considered in private alpha.

I haven’t had the chance to actually use the api yet but I have studied the examples (there are only two) and browsed the private mailing list to better understand it. Here are a few things that I have understood about the api:

  • Each client connection is called a “Channel”. There can only be one active channel per client and it is identified by a unique id.
  • XMPP is used for transferring messages, not websockets. This is accomplished by embedding a hidden Google Talk iframe in the application. The javascript api does this automatically.
  • The intent of the API is to allow multiple clients (browsers) to share messages instantaneously (eg: chatting). It is not designed for server-side streaming which really goes against the grain of app engine.
  • Websocket support may be implemented in the future.

The basic javascript client code is quite simple:

     var channel = new goog.appengine.Channel(channel_id);
      var socket = channel.open();
      socket.onopen = function() {
        window.setTimeout(function() {sendMessage('connected')}, 100);
      }
      socket.onmessage = function(evt) {
          var o = JSON.parse(evt.data);
          ... app logic ...
        }

and the server-side Python code is not too bad either:

from google.appengine.api import channel
from google.appengine.api import users

# creating a channel
user = users.get_current_user()
id = channel.create_channel(user)

# sending a message to that channel later in the code
channel.send_message(user, "json formatted message")

As you can see, the API is quite simple. Hopefully it will prove to be a boon for developers trying to build distributed multi-user/multi-player applications using the app engine platform.

UPDATE 12/2: The Channel API is now publicly available in v 1.4.0 of the SDK.