Comments (2)
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.
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)
- No route to host----when access IPv6 address failed,no attempt was made to access an IPv4 address HOT 1
- How to close a client connection using the threading interface while stuck in ClientConnection.recv
- Can we get more attention in the threaded client interface? HOT 1
- Human-readable representation of a frame is too short HOT 2
- No module websockets.imports HOT 2
- Sync client stops process exit when running in a Thread if not explicitly closed HOT 5
- Python 3.11 incompatible with websockets\legacy\protocol.py Error "got an unexpected keyword argument 'loop'" HOT 1
- Strange problem, client cannot receive messages from the server, after sending a certain amount of messages. HOT 2
- Cannot Send message to a single client.
- handling multiple websocket client connections HOT 4
- Enable to connect ! invalid handshake HOT 7
- recv() is slow HOT 5
- Client state is incorrect HOT 1
- Feature batch receive HOT 2
- [QUESTION] Switching from websocket-client to websockets HOT 1
- Sync version of broadcast HOT 2
- Running Scheduled Task in Websokcets Or Scaling with multiple workers HOT 1
- await websocket.recv() block the coroutine loop. HOT 1
- When using websockets as a client, how to send a pong when receiving a ping? HOT 1
- Make MAX_LINE configurable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websockets.