How can I run a WebSocket server on top of Google App Engine? Is it possible? Will it be possible?
10 Answers
Is it possible?
No.
You can't right now because GAE doesn't allow generic inbound socket connections. Each request is also limited to 30 seconds but this could easily be worked around with automatic reconnection and session tracking.
Will it be possible?
Probably.
Google has been one of the biggest (main) promoters of the WebSockets standard. I would be surprised if they don't push support for it into GAE at some point in the future. Note that the WebSockets draft standard is still in flux so Google might be hesitant to add support before the standard is more solid.
Here is the bug for WebSockets support on GAE: http://code.google.com/p/googleappengine/issues/detail?id=2535
Note that a google employee indicates it's not on the roadmap but that they know it would be useful. That's about as positive an answer as you get from google about features that have not been announced. I recommend adding your voice to that bug in favor of WebSocket support. It can't hurt.
Also, depending on your application, you may consider the Channel API which will likely have GAE support soon:
- http://googleappengine.blogspot.com/2010/05/app-engine-at-google-io-2010.html
- http://bitshaq.com/2010/09/01/sneak-peak-gae-channel-api/
EDIT (2015): the Channels API is available now (it has been for a while).
All of these answers are out of date.
The Channel API has been deprecated. Google strongly recommends you use Firebase.
It is also worth noting, that Google has now released the flexible environment.
With the flexible environment, you could easily allow socket connections, or use Python 3.
It's officially supported now.
See https://cloud.google.com/appengine/docs/python/channel/
EDIT: the Channel API is supported, not WebSockets. The Channel API is built on WebSockets, but it doesn't give you direct access to the WebSocket. I suppose it's good enough for typical Web apps.
As of January 9, 2019 it is officially in Beta now - but only for App Engine flexible. For example, see the Python documentation. According to the issue tracker, it will work with any language, though.
A couple people have gotten websockets working with GAE with the help of another server... checkout http://code.google.com/p/typhoonae/wiki/WebSockets
There's also this: https://cloud.google.com/appengine/docs/go/sockets/ It's experimental and very low level though.
June 2019
Websocket support for GAE is now supported under SLA for Flex.
Hi everyone, I'm happy to announce that Websockets support
for Flex is now Generally Available! We've made no changes since Beta
but Websockets traffic is now subject to our SLA.
We've also published documentation for this feature for all App Engine Flex languages.
See https://issuetracker.google.com/issues/35886348#comment285