问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/35190045/websocket-ws-ssl