-
Notifications
You must be signed in to change notification settings - Fork 46
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
implement an asyncio version of the websocket class #13
base: esp8266
Are you sure you want to change the base?
Conversation
This looks pretty good. Truthfully, I wonder if this should be the default implementation. I would have made it the default implementation originally (there's a branch even), but asyncio wasn't implemented on the target ESP platform at the time. What do you think? There's not a lot of point in maintaining two implementations (truthfully I don't even maintain one implementation). |
I'm not sure about default vs. not. The times I've used websockets in past projects, it's always been in an asynchronous way. But if someone wanted to use them in a synchronous project and this was the default, they would have to do some gymnastics due to the async keyword. |
@RobertBlackhart Hello, have you tested it widely? Arey you crrently using your fork lib? I'm interested in using it. Or maybe you know about other alternatives to use websocket on Micropython (Pi Pico). Thank you |
I'm afraid that the project that I made this change for was shelved. In my limited testing it was working, but I wasn't using it in anything I would call production-ready and I haven't even run it in a few years. Sorry I don't have much more experience I can offer besides what's in the diff and the thread here. If you decide to try it, don't forget to update if it's working for you so that the next person has more to go on :) |
@RobertBlackhart okay, thank you. I will try to use the C/C++ way but if I achieve any improvement here I will let you know ;) |
|
||
elif length < (1 << 16): # Length fits in 2-bytes | ||
byte2 |= 126 # Magic code | ||
await self.srwriter.awrite(struct.pack('!BBH', byte1, byte2, length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the state of this PR but just noticed this typo when I was playing around with it on my Raspberry Pi Pico W.
await self.srwriter.awrite(struct.pack('!BBH', byte1, byte2, length)) | |
await self.swriter.awrite(struct.pack('!BBH', byte1, byte2, length)) |
This change allows the uwebsockets package to be used inside of a uasyncio application by using the StreamWriter and StreamReader classes.
The client and protocol logic is almost not touched at all other than to change the method of reading and writing.