-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Simple example of uasyncio WebSocket Server (secure - with SSL) #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can look here. Not sure about quality, never used. https://github.com/jczic/MicroWebSrv |
That use thread, not uasyncio. |
Look at Picoweb. It uses uasyncio by Paul Sokolovsky. |
Hello @bazooka07
The Picoweb do not support websocket. Even uasyncio on PicoWeb is old, it is not the official v3 uasyncio compatible, but it is good start point. The https://github.com/jczic/MicroWebSrv use WebSocket, but is not official This project https://github.com/Carglglz/upydev/tree/master/upyutils has a WebREPL example working with SSL using the official uwebsocket module - that is great. This project was put as a PR (#5611) to support SSL in the official WebREPL, but I do not know why still not was merged, after two years. I need just to know now how to add uasyncio on that WebREPL + SSL example. |
|
@Carglglz Excellent!
Sorry for my ignorance, but think that already working on the Microdot, like as show this example echo_async_tls.py working with this index.html that use Please, let me know what I missing. I'm a bit confuse now: how that (uasyncio WebSocket Server (secure - with SSL)) already working on Microdot if the #8968 is a new implementation to have that working? Thank you in advance! |
@beyonlo I think those examples only work with CPython at the moment?, unless I'm missing something in that example import ssl
from microdot_asyncio import Microdot, send_file
from microdot_asyncio_websocket import with_websocket
app = Microdot()
@app.route('/')
def index(request):
return send_file('index.html')
@app.route('/echo')
@with_websocket
async def echo(request, ws):
while True:
data = await ws.receive()
await ws.send(data)
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
sslctx.load
8000
_cert_chain('cert.pem', 'key.pem')
app.run(port=4443, debug=True, ssl=sslctx) Right now MicroPython This calls asyncio.run(self.start_server(host=host, port=port, debug=debug,
ssl=ssl)) which calls try:
self.server = await asyncio.start_server(serve, host, port,
ssl=ssl)
except TypeError:
self.server = await asyncio.start_server(serve, host, port) And if you look at async def start_server(cb, host, port, backlog=5): Also this comment from @miguelgrinberg in the issue you opened in #34
Well, with the latest changes to #8968 the async support is enabled, so those examples will work in MicroPython too. 😄 |
@Carglglz Ohh, you are right, that echo_async_tls.py do not works with MicroPython. As I still developing using as base example just the echo_async.py (WebSocket Server without SSL) and just when the entire application will be stable that I was thinking do add the ssl, that was the reason that I never had tested the echo_async_tls.py on the MicroPython.
Yes, I remember now about that moment. Maybe a good idea, as suggstion, is @miguelgrinberg add a note in the that README.md (inside tls examples) talking about that the echo_async_tls.py works (for now :) ) just on the CPython.
Excellent, so maybe sooner the echo_async_tls.py will works on MicroPython as well :) Thank you for the explanation! |
…n-main Translations update from Hosted Weblate
Asyncio now supports SSL server and client mode. So that's the first and main step to getting secure WebSockets. |
Uh oh!
There was an error while loading. Please reload this page.
Hi all.
I would like a simple example of uasyncio WebSocket Server (secure - with SSL). I see that there is a official
uwebsocket
module implemented on MicroPython.Well, so I found a example (https://github.com/micropython/micropython/blob/master/extmod/webrepl/webrepl.py) that use the official
uwebsocket
module. Need just to add SSL + uasyncio on that example.Thank you in advance!
The text was updated successfully, but these errors were encountered: