3

I'm using Google App Engine/Managed VMs to develop a nodeJS application using web sockets.

As part of the app, the front end needs to connect using Websockets e.g.

connection = new WebSocket('wss://127.0.0.1:3001');

The bit that I'm struggling with is how to ensure that the SSL part works. My current code to start the WebSocketServer is:

var WebSocketServer = require('ws').Server;

var wss = new WebSocketServer({port:3001});

but this only creates a standard server (ie ws://127.0.0.1:3001).

My question is, using WebSocketServer, how do I create a WebSocketServer for use with SSL?

TStu
  • 244
  • 3
  • 15
  • Yeah, sadly we just don't support websockets yet. If you don't want to stand up your own VM as described below, pubnub is another nice option: https://www.pubnub.com/documentation/ – Justin Beckwith Feb 11 '16 at 17:29
  • I found this in search results for `node einaros https`, but the accepted answer didn't help me. In case anyone else finds this, here's a related question [How to Create Secure (TLS/SSL) Websocket Server?](http://stackoverflow.com/q/31338927/722036) with my answer posted. Tried to eliminate the confusion, so hopefully this helps someone. – ᴍᴇʜᴏᴠ Mar 25 '16 at 01:21

1 Answers1

2

Using secure WebSockets requires an SSL cert, and using a self-signed cert is an option. There is a tutorial which may be useful for getting this set up.

Using WebSockets on Managed VMs may present other problems though due to port forwarding issues from the appspot.com frontend. There is a public issue which details this as well as another question on Stack Overflow. You may need to use full Compute Engine instances instead of Managed VMs as a workaround.

Community
  • 1
  • 1
Adam
  • 5,697
  • 1
  • 20
  • 52
  • Cheers for the reply. I've searched high and low but can't find any examples on how to run Secure Websockets on GCE but keep running into issues. I keep getting the error Bad Request 400. Do I have to refer to the websocket by ip, or can I refer to it by site/domain? – TStu Feb 08 '16 at 22:14
  • You can refer to sockets by IP or by domain as long as you have a static IP set up for the instance and the relevant domain mapping set up. You may want to consider opening a new question for issues with WebSockets on GCE regarding the 400. – Adam Feb 10 '16 at 01:01