How can I implement a secure WebSocket (wss://) server in Python?

后端 未结 5 2037
情深已故
情深已故 2021-01-31 20:00

I want to serve a real-time stream that has to be securely encrypted due to sensitive data.

I\'ve successfully got normal WebSockets streaming using both gevent and guni

5条回答
  •  -上瘾入骨i
    2021-01-31 20:57

    You can check out the websockify project. Websockify is a proxy that allows a WebSockets capable browser to communicate with a raw binary TCP server. It does this by base64 encoding all traffic to/from the browser. However, the project is modular and the websocket.py file is a general WebSocket server that is designed to be extended (and there a couple of included tests that show how this works). It would be fairly easy to disable the base64 encoding if that is not needed for you project.

    Websockify also includes a Javascript library 'websock.js' which is designed to interact with websockify. It will transparently fallback to using web-socket-js (Flash based) if the browser does not have native WebSocket support.

    Websockify supports secure (TLS/wss) connections and also is able to answer Flash security policy requests inline on the same port.

    Disclaimer: I made websockify.

提交回复
热议问题