【问题标题】:Real-time Gaming with Node.js + WebSocket in Google Cloud Platform tutorial?Google Cloud Platform 教程中使用 Node.js + WebSocket 进行实时游戏?
【发布时间】:2016-04-27 16:56:50
【问题描述】:

我是一名前端开发人员,想在浏览器中使用 websocket+node.js 进行游戏。 我要的是一个关于如何在谷歌云中工作的很棒的教程或任何其他帮助。

我发现是这样的: https://cloud.google.com/solutions/real-time-gaming-with-node-js-websocket 但是我对服务器端不是很熟悉,而且对谷歌平台是全新的,所以它对我没有多大帮助。

我有一个简单的套接字示例,只要它在我的本地环境中就可以工作,但是当我部署它时,控制台中会出现很多奇怪的错误。

你可以在这里找到 http://socket-1281.appspot.com/

控制台日志中有错误提示:

WebSocket connection to 'ws://socket-1281.appspot.com/socket.io/?EIO=3&transport=websocket&sid=BXTZAZbQVQYA1TBLAAAA' failed: Error during WebSocket handshake: Unexpected response code: 400
Failed to load resource: the server responded with a status of 400 (Bad Request)

那么有谁知道如何解决这个问题或在哪里寻求帮助?

这里是源 https://app.box.com/s/a3ma8ivel1qj378m9nh7s9q1e3xreo7n

【问题讨论】:

  • 那么您可以检查控制台的实际错误。查看完整的系统然后找出错误确实不容易。
  • 我搜了一下,发现它可能和一个叫nginx的东西有关。

标签: node.js websocket socket.io google-compute-engine google-cloud-platform


【解决方案1】:

Google App Engine 的负载均衡器不支持 websocket。如果您尝试连接到 socket-1281.appspot.com,它将通过负载均衡器并且无法工作。您需要做的是通过直接连接到您的实例来避免负载均衡器。

这是一个可能有帮助的示例: https://github.com/thebergamo/appengine-websocket-nodejs#how-to-setup-the-deployment-environment

【讨论】:

  • 太棒了!似乎是我正在寻找的东西。在 index.html 它说 var host = 'your-ip';当我将它部署到 GAE 时,我应该在此处放置什么?
  • 在该页面的自述文件中写道:Google App Engine -> Instances - Change the option Managed to User. Next you need set the IP to static.。因此,无论实例当时的 ip 是什么,都应该是您用于“您的 ip”的那个。
  • Obrigado!这回答了我的第二个问题。但是那个ip不会变吗?
  • 它在 App Engine 实例的外部 IP 上显示为 ephemeral。
  • 您可以将临时外部 IP 地址升级为静态外部 IP 地址。欲了解更多信息,请访问this link
猜你喜欢
  • 2018-12-15
  • 2020-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-14
  • 2020-02-05
  • 1970-01-01
  • 2021-01-15
相关资源
最近更新 更多