As you can read from the docs 
<https://cloud.google.com/appengine/docs/python/channel/javascript>, the 
Channels API client depends on importing from your app's special route: 
/_ah/channel/jsapi. This special route redirects to 
https://talkgadget.google.com/talkgadget/channel.js, where you'll find a 
very well-obfuscated and minified JS client which allows you to use the 
magic Channel API methods like "onopen", "onmessage", "onerror", and 
"close". 

You can use a JS beautifier to see the code, but as you will see it's quite 
complex. The Channels API mirrors closely the server-sent events standard, 
as you can see from inspecting the methods available in the W3C doc 
<http://www.w3.org/TR/eventsource/#the-eventsource-interface>you linked 
("onopen", 
"onmessage", "onerror"), and has a very similar use-case profile, although 
it isn't compliant with the standard.

You could attempt to declare "Content-Type: text/event-stream" on your own 
vanilla App Engine handler, and use an EventSource 
<https://developer.mozilla.org/en-US/docs/Web/API/EventSource>object in the 
browser to initiate a keep-alive connection. The problem is, App Engine 
waits for the handler on your app to return fully before flushing the 
buffer and sending the response data. You can find this documented here 
<https://cloud.google.com/appengine/docs/java/requests#Java_Responses> for 
java, here 
<https://cloud.google.com/appengine/docs/python/requests#Python_Responses> for 
python, here 
<https://cloud.google.com/appengine/docs/php/requests#PHP_Responses> for 
php, and here 
<https://cloud.google.com/appengine/docs/go/requests#Go_Responses> for 
go. What this means in practice is that your stream will not be 
"keep-alive" and will close each time one response is sent. Or, if you 
implement your server-sent event code server-side as most people do, it 
will buffer up all of its responses and finally send them all only when it 
terminates. 

Neither of these cases are all that desirable, since the first breaks the 
some of the efficiency of server-sent events by requiring the connection to 
be recreated each time (the polling code which powers EventSource in the 
browser will still, however, make things appear more or less smooth and as 
you want; you won't be able to gain much meaningful information from 
open/close events, however). The second case will break the function of 
server-sent events entirely.

There's already a public issue tracker thread requesting Web Sockets for 
GAE, and even one person in the thread 
<https://code.google.com/p/googleappengine/issues/detail?id=2535#c45> has 
mentioned server-sent events, but it doesn't have its own feature request 
thread yet, and they are quite separate <http://stackoverflow.com/a/8800255> 
technologies. 
I encourage you to create a feature request to allow server-sent events on 
App Engine, either as part of the Channels API or otherwise.

It seems as though you'd have more success with Compute Engine 
<https://cloud.google.com/compute/> if you want to use server-sent events 
as they should be, today. I can't comment on the GAE roadmap or any 
timeline for feature implementation but I still figured I would gather a 
lot of information so you know exactly the state of everything. I encourage 
you again to create a public issue tracker thread and get as many users to 
star it as you can.

Hope this helped answer your question,

Nick

On Tuesday, June 2, 2015 at 1:53:33 AM UTC-4, Robert Stepanek wrote:
>
> Is the Channels API planned to support the Server-Sent Events W3C 
> Recommendation (http://www.w3.org/TR/eventsource/)? Given that this 
> standard is pushed by Google it would be great to also use it on App 
> Engine. Or does it work already with the current Channels implementation?
>
> Many thanks,
> Robert
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/be85b8ef-b8ad-44c5-ad5c-844e023317d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to