我使用websockets来获取websocket服务器。哪个工作得很好。但现在我想使用wss进行安全连接。 here它说you can set the ssl keyword argument to a SSLContext to enable TLS.
,这就是我所做的。
import asyncio
import websockets
import ssl
from subprocess import check_output
import sys
async def onConnect(websocket, path):
while 1:
msg = await websocket.recv()
from subprocess import check_output
out = check_output(["./wsscript.sh", msg])
resp = out.decode("utf-8")
print("< {}".format(resp))
await websocket.send("{}".format(resp))
ctx=ssl.create_default_context()
ctx.load_cert_chain('./cert.pem', './key.pem')
start_server = websockets.serve(onConnect, '10.220.1.2', 8765,ssl=ctx)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
但是我无法使用SSLContext
连接到websocket