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

Add functions to allow proper subclassing of WebSocket*Protocol #32

Closed
Elizafox opened this issue Sep 16, 2014 · 2 comments
Closed

Add functions to allow proper subclassing of WebSocket*Protocol #32

Elizafox opened this issue Sep 16, 2014 · 2 comments

Comments

@Elizafox
Copy link

As seen with the echo server example, https://docs.python.org/3/library/asyncio-protocol.html#echo-server - I would like to be able to use a subclass of WebSocket*Protocol (in my case the server) and override methods similar (perhaps not the same) as those to implement desired functionality. I could make a thin wrapper class that emulates this if it would be considered useful.

@aaugustin
Copy link
Member

I'm really sorry, but I don't get what changes you're asking for.

Here's an example of subclassing WebSocketServerProtocol:
https://github.com/aaugustin/websockets/blob/master/compliance/test_server.py#L11-L20

If that doesn't answer your question, maybe you could show me what you're trying to do, what results you get, and explain what results you would expect?

Otherwise, is this an issue with the documentation?

Thanks!

@aaugustin
Copy link
Member

Just after writing that comment, I noticed DCP-Project/minnow-prototype@1153086#diff-017639d70cd2c855d3f7c4ed46c3b2c2R362.

If I understand correctly, you would like to be able to handle incoming websocket messages through callbacks rather than by defining a handler.

Considering the design of the API and the current implementation, this is rather hard. I would need an incremental parser, which I haven't implemented. Writing everything with coroutines makes the code much simpler (as you might expect — that's pretty much the point of asyncio).

Choosing coroutines over callbacks was an early design decision of the project. Later I realized it would prevent some use cases, but that's the way I wanted to write it and it don't see any useful way to refactor it.

Your best chance is to write a websocket handler that reads messages in a loop and calls the callback whenever it gets a message, which is what you did. I don't understand entirely why you have so much code around, because I don't know the context, but that was the right idea if you want to use my library.

Maybe you should use another library, there's a few hanging around.

@aaugustin aaugustin mentioned this issue Jun 23, 2019
18 tasks
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

No branches or pull requests

2 participants