Skip to content
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

Open
wants to merge 2 commits into
base: esp8266
Choose a base branch
from

Conversation

RobertBlackhart
Copy link

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.

@danni
Copy link
Owner

danni commented Feb 18, 2020

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).

uaiowebsockets/protocol.py Outdated Show resolved Hide resolved
@RobertBlackhart
Copy link
Author

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.

@busslina
Copy link

@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

@RobertBlackhart
Copy link
Author

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 :)

@busslina
Copy link

busslina commented Feb 12, 2023

@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))

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.

Suggested change
await self.srwriter.awrite(struct.pack('!BBH', byte1, byte2, length))
await self.swriter.awrite(struct.pack('!BBH', byte1, byte2, length))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants