在Google Cloud Platform教程中使用Node.js + WebSocket进行实时游戏?

时间:2016-04-24 14:03:56

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

我是一名前端开发人员,希望在浏览器中使用websocket + node.js进行游戏。 我要求的是一个很棒的教程,介绍如何在Google Cloud或其他任何帮助中解决这个问题。

我发现的是: 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

1 个答案:

答案 0 :(得分:2)

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

以下示例可能有所帮助: https://github.com/thebergamo/appengine-websocket-nodejs#how-to-setup-the-deployment-environment