如何在 Tornado 中使用安全的 websocket (wss) [英] How to use secure websocket (wss) in Tornado

查看:52
本文介绍了如何在 Tornado 中使用安全的 websocket (wss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Tornado 和网络服务的新手.在我的应用程序中,我在服务器端有 Qt/c++ 客户端和 python Tornado.Qt 客户端以文本消息的形式发送命令(例如ws://192.121.1.213:8080?function=myfunction?args=params..").现在,我想使用安全网络套接字,即 wss 代替 ws.服务器端和客户端需要哪些更改?指向任何在线示例的指针也会有所帮助.谢谢.

I'm new to Tornado and web services in general. In my application, I've Qt/c++ client and python Tornado on server side. The Qt client sends commands in the form of text messages(e.g. "ws://192.121.1.213:8080?function=myfunction?args=params..").Now, I want to use secure web socket i.e. wss in stead of ws. What changes are required on server and client side? Pointer to any online example would be also helpful. Thanks.

推荐答案

在构建 HTTPServer 时传递 ssl_options 参数:

Pass the ssl_options argument when constructing your HTTPServer:

ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
                        os.path.join(data_dir, "mydomain.key"))
HTTPServer(applicaton, ssl_options=ssl_ctx)

http://www.tornadoweb.org/en/stable/httpserver.html#http-server

这篇关于如何在 Tornado 中使用安全的 websocket (wss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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