简体   繁体   English

使用套接字和 NodeJs 的 Google App Engine

[英]Google App Engine using sockets with NodeJs

I'm using Google App Engine to run a node js application and it works.我正在使用 Google App Engine 运行节点 js 应用程序,并且它可以工作。 The issue is that I want to run another node js application which is actually a websocket and searching on the internet and the docs, I found that they support now sockets (before they didn't)!问题是我想运行另一个 node js 应用程序,它实际上是一个 websocket 并在互联网和文档上搜索,我发现它们现在支持套接字(之前不支持)!

The only thing is that the node js documentation is missing or they still do not support sockets only for node js, but I can't find the answer for that.. Maybe someone have a work around for that.唯一的问题是缺少 node js 文档,或者它们仍然不支持仅用于 node js 的套接字,但我找不到答案.. 也许有人可以解决这个问题。

Please, do not suggest using Google Compute Engine to run my websocket server, I know that works.请不要建议使用 Google Compute Engine 来运行我的 websocket 服务器,我知道这可行。

If you're using Google App Engine Flexible, websocket are available in beta.如果您使用的是 Google App Engine Flexible,则可以使用测试版的websocket

I used that example and deployed it on App Engine Flex, and it works我使用了那个例子并将它部署在 App Engine Flex 上,它工作正常

Since not all clients support websockets, a common workaround is to use Socket.IO由于并非所有客户端都支持 websockets,一个常见的解决方法是使用Socket.IO

If you will be using Socket.IO you will need to change the session affinity in your app.yaml like so如果您将使用 Socket.IO,则需要像这样更改 app.yaml 中的会话关联

network:
  session_affinity: true

You will find more information about that here您将在此处找到更多相关信息

This app.yaml configuration worked for me:这个 app.yaml 配置对我有用:

runtime: nodejs env: flex manual_scaling: instances: 1 network: session_affinity: true

And I enabled the firewall rules by this command:我通过这个命令启用了防火墙规则:

gcloud compute firewall-rules create default-allow-websockets --allow tcp:65080 --target-tags websocket --description "Allow websocket traffic on port 65080"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM