WebSocket WS SSL [英] WebSocket WS SSL

查看:181
本文介绍了WebSocket WS SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine/托管VM通过Web套接字开发nodeJS应用程序.

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

作为应用程序的一部分,前端需要使用Websockets连接 例如

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

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

我苦苦挣扎的一点是如何确保SSL部分正常工作. 我当前启动WebSocketServer的代码是:

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});

但这只会创建一个标准服务器(即ws://127.0.0.1:3001).

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

我的问题是,使用WebSocketServer,如何创建用于SSL的WebSocketServer?

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

推荐答案

使用安全的WebSockets需要SSL证书,并且可以选择使用自签名证书.有一个教程可能对进行此设置很有用.

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.

尽管由于来自appspot.com前端的端口转发问题,在受管VM上使用WebSocket可能还会出现其他问题.有一个公开问题,其中对此进行了详细介绍有关堆栈溢出的问题.解决方法,您可能需要使用完整的Compute Engine实例而不是托管VM.

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.

这篇关于WebSocket WS SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆