Comments (9)
This is probably a good idea, however, it's a breaking API change: ws.send() would become a coroutine, while it's currently a function.
For the record, drain()
was added to asyncio
recently. It didn't exist when I wrote most of the current implementation.
from websockets.
Not necessarily, it should be possible to simply add a drain()-like method to the exposed API.
It's like the asyncio API. If you do heavy streaming, you should yield from drain() after sending. If you are only transferring a bit of json, well, do not care.
Because the current implementation does not use StreamWriter, this functionality should be implemented using a future and the following callbacks:
BaseProtocol.pause_writing()
Called when the transport’s buffer goes over the high-water mark.
BaseProtocol.resume_writing()
Called when the transport’s buffer drains below the low-water mark.
This functionality is critical for every bandwidth-hungry websocket application.
from websockets.
I'd rather have the library handle this behind the scenes. It's focused on simplicity.
I don't want to inflict flow control on my users and certainly not with a low-level API.
The point of this library is to provide a high-level API that "just works" -- even if it's not the fastest websockets library on Earth.
Changing the API just means I have to release a 2.0. There's nothing wrong with that.
from websockets.
You are right, it would be simpler and better. Version 2.0 sounds good, definitely a huge improvement for streaming apps (I'm working on a terrain streaming app with high bandwidth requirements).
from websockets.
I'm currently working on making WebSocketCommonProtocol inherit from StreamReaderProtocol.
This convenience API was also added recently and appears suitable for this use case.
That will make WebSocketCommonProtocol use StreamWriter and make flow control possible through private (undocumented) attributes -- ie. you will be able to yield from ws.writer.drain()
. This workaround will allow you to move forward while I think about a more general solution.
from websockets.
=) Awesome. That will do it.
from websockets.
In my pull request, the protocol uses a StreamWriter. If you can try it and confirm that yield from ws.writer.drain()
does what you expect, that would be great.
from websockets.
I can confirm that it does work great. Thanks!
from websockets.
Cool. I'm going to merge the patch now.
I think I'll wait until Python 3.4 final is released to make a new release of websockets, in case asyncio changes again. Hopefully you can work with the master until then.
from websockets.
Related Issues (20)
- When using websockets as a client, how to send a pong when receiving a ping? HOT 1
- Make MAX_LINE configurable HOT 5
- When I use websocket to transmit continuous audio pcm data to the server, half of the data is lost HOT 1
- websocket over stomp received Session closed error HOT 5
- Connection breaks in between during a sustained transfer HOT 9
- When there are N channels in a group, sending a message to the group will be sent N times HOT 1
- Asking for Guidance in Writing a WebsocketHandler for the Python logging Module HOT 3
- iOS and WebSockets: 0 bytes read/no close frame received/code 1006? HOT 5
- question: intended behavior with failed auth and async for auto-reconnect HOT 29
- Clean up tests on PyPy HOT 4
- Inconsistent raw frames when sending a custom text frame with an empty body HOT 3
- Expose list of connections as an attribute of WebSocketServer HOT 1
- Client initiated close always runs into `close_timeout` HOT 3
- Threading server should close connections on exit HOT 1
- Respond with HTP 414 or 431 when exceeding security limits
- Multiple clients from localhost HOT 2
- speedups.c is missing from the 13.0 source distribution HOT 4
- Unittest failing with “ AttributeError: module 'typing' has no attribute 'StatusLike' ” HOT 1
- websockets.asyncio.connection.Connection.recv is replacing all RuntimeError exceptions HOT 5
- About Log Message Formatting on Reconnect 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.