alin miu google app engine(gae) v1.1

11

Click here to load reader

Upload: google-developer-group-bucharest

Post on 18-Jul-2015

160 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Alin miu google app engine(gae) v1.1

Google App Engine

Real-time communication using Channel API

Page 2: Alin miu google app engine(gae) v1.1

What Is Google App Engine(GAE)?

• Google App Engine lets you run web applications on Google's infrastructure.

• With App Engine, there are no servers to maintain: you just upload your application, and it's ready to serve your users.

• Google App Engine applications can currently be written

in Java, Python, or Go.

Page 3: Alin miu google app engine(gae) v1.1

Push and Pull

• Pull:– AJAX

• Push:– WebSockets

Page 4: Alin miu google app engine(gae) v1.1

Channel API(Push)

• Creates a persistent connection between your application and Google servers

• Allows your application to send messages to JavaScript clients in real time without the use of polling.

Page 5: Alin miu google app engine(gae) v1.1

Channel API(Push)

Javascript Client:– Connecting to the channel once it receives the channel’s unique

token from the server– Listening on the channel for updates – Sending update messages to the server

The Server:– Creating a unique channel for individual JavaScript clients– Creating and sending a unique token to each JavaScript client

so they may connect and listen to their channel– Receiving update messages from clients via HTTP requests– Sending update messages to clients via their channels– Optionally, managing client connection state.

Page 6: Alin miu google app engine(gae) v1.1

Channel API(Push)

The Client ID:– The Client ID is responsible for identifying individual JavaScript

clients on the server.– A Client ID can be anything that makes sense in the design of

your application.

Tokens:– Tokens are responsible for allowing the JavaScript Client to

connect and listen to the channel created for it. – The server creates one token for each client using information

such as the client’s Client ID and expiration time.– Tokens expire after two hours and should also be treated as

secret.

Page 7: Alin miu google app engine(gae) v1.1

Channel API(Push)

The Channel– A channel is a one-way communication path through which the

server sends updates to a specific JavaScript client identified by its Client ID.

– The server receives updates from clients via HTTP requests, then sends the messages to relevant clients via their channels.

The Message– Messages are sent via HTTP requests from one client to the

server. – Once received, the server passes the message to the

designated client via the correct channel identified by the Client ID.

– Messages are limited to 32K.

Page 8: Alin miu google app engine(gae) v1.1

Channel API(Push)

Page 9: Alin miu google app engine(gae) v1.1

Channel API(Push)

Page 10: Alin miu google app engine(gae) v1.1

Channel API(Push)<body> <script> channel = new goog.appengine.Channel('{{ token }}'); socket = channel.open(); socket.onopen = onOpened; socket.onmessage = onMessage; socket.onerror = onError; socket.onclose = onClose; </script></body> sendMessage = function(path) {

path += '?g=' + message; var xhr = new XMLHttpRequest(); xhr.open('POST', path, true); xhr.send();};

Page 11: Alin miu google app engine(gae) v1.1

Demo: http://gdg-bucharest.appspot.com