WebSocket WS SSL

家住魔仙堡 提交于 2020-07-19 05:05:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!