Google App Engine/Compute Engine with Socket.IO

2019-08-23 16:19发布

Having launched my NodeJs app on AppEngine, i found it throws an exception: app.min.js:20 WebSocket connection to 'wss://hostname/socket.io/?EIO=3&transport=websocket&sid=OClcQulfAmcJEpfMAAAV' failed: Error during WebSocket handshake: Unexpected response code: 400

Trying to google, i found Google Cloud does not seem to support WebSockets. Since app is written and we have no much time to rewrite it, are there any other ways to keep things as is and have socket.io working with Google Cloud? Is it possible to run Socket.IO server separately and communicate through it? Having app moved into standalone VM on Compute Engine could solve it or sockets are`t supported even there?

Follow up: i found it works on Chrome though, as it switches automatically to pooling transport.

2条回答
姐就是有狂的资本
2楼-- · 2019-08-23 17:03

It can be done using Flexible Environment running Node.js. However,

Note: Secure WebSockets are currently not supported by App Engine Flexible Environment. WebSockets will only work if you load your page over HTTP (not HTTPS).

https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/websockets

Edit: To add, there is a beta that supports Web Sockets for GAE using typhoonae. Here's the link for those interested: https://code.google.com/archive/p/typhoonae/wikis/WebSockets.wiki

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-08-23 17:05

Using Google App Engine as web frontend and running socket.io in a virtual machine (for long lived client connections) also offers a scalable solution. A scalable architecture from a real time gaming app on google cloud platform

查看更多
登录 后发表回答