4 ms·
> Sure it does. WS is just a framing protocol on top of a regular TCP connection. Though it sounds like you're not talking about the protocol so much as the Jav
by anderspitman 7y ago
> Sure it does. WS is just a framing protocol on top of a regular TCP connection. Though it sounds like you're not talking about the protocol so much as the JavaScript API, which perhaps doesn't give you enough visibility into the underlying TCP socket state.
Every WS implementation I've ever seen is nonblocking on both sides. Are you aware of any that aren't? I'm not even sure the spec allows for that.
But yes you are correct that you can implement more advanced algos on top.
EDIT: Sounds like blocking implementations do exist, but unfortunately I'm constrained to a browser environment, and all the browsers are nonblocking.
- zenhack 7y agooff the top of my head https://godoc.org/golang.org/x/net/websocket https://godoc.org/golang.org/x/net/websocket has a synchronous read/write api
- anderspitman 7y agoDoes that block until messages are actually transferred, or just shove them in a golang buffer and return? Now that you mention it I feel like maybe I have seen blocking implementations in golang and Python a while back, which would make sense.
- zenhack 7y agoSkimming the implementation, there is buffering, but it looks like it's bounded, so tight looping Write() you should still end up blocking on the OS at some point.
- anderspitman 7y agoMakes sense. Thanks for correcting my misconception!
- kentonv 7y agoHeh. The WebSocket implementation I wrote for KJ does in fact provide backpressure (the send() method returns a promise that resolves when it's a good time to send the next message). I guess I'm surprised to hear that most don't...
- anderspitman 7y agoI think it's more likely I've just been too deep in JS-land. Does KJ send() do any internal buffering, or wait for the OS to tell it to send more?
- kentonv 7y agoIt waits for the OS.
- decentralised 7y agoI've been looking into streams in detail recently because I'm preparing for the OpenJSF exam... maybe this is relevant to you too: https://nodejs.org/es/docs/guides/backpressuring-in-streams/ https://nodejs.org/es/docs/guides/backpressuring-in-streams/
- anderspitman 7y agoThanks for the link. I'm actually quite familiar with that article. It's been very useful for me when designing omnistreams. You may find some of the links on the bottom of this page useful: https://github.com/omnistreams/omnistreams-spec https://github.com/omnistreams/omnistreams-spec