Run Websocket on GAE

In order to use websockets, you must use the Google Managed VM with custom runtime.

https://cloud.google.com/appengine/docs/managed-vms/custom-runtimes

Once that is running, you will need to access that server directly by ip or cname. You cannot go through the appspot.com domain.


Later a lot of hours study and tests, a friend in Google show me one solution for this problem! Thanks Thiago Avancini!

Well, the solution is:

The first step is using the managed-vms. (The repo use it.) But the goal is switch the managing from Google to User. When you do this, the next step is create an static IP for your application. On my case I using the port 3000 to serving my Websocket, feel free to change. On my app.yaml I enable this port too like this:

network:
  forwarded_ports: ["3000"]

Remember to enable this port on the proxy in "network>>default>>firewall".

If you deploy the application via gcloud, you need enable again on your application the user management and the static IP.

I'll send to GoogleCloudPlatform this repo for will be a sample for using websockets on AppEngine.


Update: February 4, 2019

Google Announced WebSockets support for the App Engine Flexible Environment

WebSockets is available to your App Engine Flexible Environment application with no special setup. Take a look at our documentation to learn more: Python | Java | Nodejs.

You must add to your app.yaml

network:
  session_affinity: true