本文介绍了在Google Compute Engine(GCE)中允许WebSockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Compute Engine(GCE)通过Socket.IO(Node.js)运行我的套接字服务器

I'm using Compute Engine (GCE) to run my socket server with Socket.IO (Node.js)

仅适用于轮询.当我尝试使用Web客户端时,收到以下错误代码:

It's only working with polling. When I try to use a web client I receive this error code:

WebSocket connection to 'ws://myapp-socket.appspot.com/socket.io/?EIO=3&transport=websocket&sid=Tt4uNFR2fU82zsCIAADo' failed: Unexpected response code: 400 

我做错了什么?是GCE配置问题吗?

What am I doing wrong? Is it GCE configuration problem?

推荐答案

使用WebSocket时,不能在脚本中使用myapp-socket.appspot.com域.相反,您将需要使用GCE实例的外部IP并直接连接到该IP,从而打开您可能正在使用的所有防火墙端口.

You cannot use the myapp-socket.appspot.com domain in your script when using WebSockets. Instead, you will need to use the external ip of the GCE instance and connect directly to that, opening any firewall ports you may be using.

我认为,进入appspot.com域的流量也正在通过前端Web服务器和socket.io,它需要直接连接到服务器.

I believe traffic going to the appspot.com domain is also going through frontend webservers and socket.io needs a direct connection to the server.

这篇关于在Google Compute Engine(GCE)中允许WebSockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 08:02