Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow WebSockets in Google Compute Engine (GCE)

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

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 

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

like image 364
rcmstark Avatar asked Dec 15 '15 07:12

rcmstark


2 Answers

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.

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.

like image 195
Jeff Deskins Avatar answered Sep 19 '22 13:09

Jeff Deskins


The Virtual Machines in Google Compute Engine have port 80 for http and port 443 for https. Using these ports for web-sockets solved the issue.

like image 24
Newton Joshua Avatar answered Sep 19 '22 13:09

Newton Joshua