GithubHelp home page GithubHelp logo

Comments (2)

aaugustin avatar aaugustin commented on June 25, 2024

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!

from websockets.

aaugustin avatar aaugustin commented on June 25, 2024

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.

from websockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.