Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

WebSocket library #1

Closed
davidbrochart opened this issue Nov 22, 2022 · 5 comments
Closed

WebSocket library #1

davidbrochart opened this issue Nov 22, 2022 · 5 comments

Comments

@davidbrochart
Copy link

Hi @frankie567, interesting project!
Out of curiosity, why did you choose wsproto over websockets?

@frankie567
Copy link
Owner

Thanks David! Well, actually I followed what Tom Christie recommended in this thread: encode/httpx#304 (comment)

Since I trust him to know way better than me what is better, I didn't question the choice 😬

@davidbrochart
Copy link
Author

Thanks for the answer, that makes sense.
I'll probably use httpx-ws very soon 😃

@Kludex
Copy link

Kludex commented Nov 23, 2022

@aaugustin Do you have a list of pros and cons about wsproto and websockets regarding the sans-io implementation?

Asking here because it may give some insights... 🤷‍♂️

@aaugustin
Copy link

aaugustin commented Nov 23, 2022

In terms of API, websockets does more for you:

  • It handles ping / pong for you — while wsproto asks you to do it
  • It handles the closing handshake for you — same comment
  • It tells you when you should close the TCP connection — the WebSocket spec requires the server to close the connection first, which causes a surprising amount of pain when you implement the closing handshake on the client side — and that drove some aspects of the design of websockets' Sans-I/O API.

In terms of performance, you should see a big difference in favor of websockets when dealing with large frames (like, 1MB) because this code in wsproto, even though it's reasonably optimized Python, is nowhere near as fast as that code in websockets. This is actually a big performance bottleneck of all pure Python implementations.

I believe that websockets a bit more battle-tested as it predates wsproto by a few years — some super-edge-case bugs were ironed out over the years.

You're welcome to have Opinions about websockets' regex-based HTTP implementation. Well, it's fast, I cannot remember having to fix embarrassing bugs, and OSS-Fuzz didn't find anything after running billions of test cases. So I guess it's a viable way implement the required subset of HTTP for a WebSocket handshake? Anyway, it doesn't matter here, as you're planning to use httpx for parsing HTTP messages.

The documentation of websockets' Sans-I/O layer tells you the basics but isn't at the same level as the documentation of the rest of the library — because so few people will integrate the Sans-I/O layer that I can support them individually. It's probably more useful to check this PR: https://github.com/aaugustin/websockets/pull/1245/files (or the actual code in the library once I merge it).

There may be other aspects in which wsproto is superior to websockets. I know where I put my efforts in websockets; I don't know where the wsproto crew invested!

Beyond that, WebSocket is a relatively small protocol so you will likely find pretty much the same code. At some point, websockets had higher performance; then everyone adopted the same ideas and I'm not sure there's a

@Kludex
Copy link

Kludex commented Nov 24, 2022

Thanks @aaugustin 🙏

Repository owner locked and limited conversation to collaborators Nov 24, 2022
@frankie567 frankie567 converted this issue into discussion #6 Nov 24, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants