WebSocket API Review
See original GitHub issueI went through the WebSocket API and wrote down my thoughts. Nothing too earth-shattering, just some ideas.
- How should WebSockets interact with the Dispatcher? In particular should open web sockets count towards
maxRequestsPerHost
? (I think yes, but we should explicitly call this out.) - When can I cancel a WebSocketCall? Once it’s open is that equivalent to calling
WebSocket#close()
? - Does
isCanceled()
return true after a WebSocket is closed? Do we throw an IllegalStateException if you write the socket in#2905onOpen()
? What aboutsendPing()
andclose()
?- It looks like pings and the corresponding pongs are very loosely coupled. Any idea how strict the spec is? Seems weird to call out that pongs can come unsolicited. I’m really unsure about what to do with pings and pongs. My first instinct is to hide them from the API and instead offer something to send pings automatically for you on a schedule
- I wonder if there’s a better name for
WebSocketListener
. WithCall
we haveCallback
and the names are cute. IsWebSocketCallback
terrible? - An obnoxious idea – would it ever make sense to combine the
WebSocketCall
andWebSocket
types? I’m getting here via the (slight) redundancy betweencancel()
andclose()
. ObviouslysendMessage()
would need to be a bit more clever to do something reasonable if it were invoked beforeonOpen()
is received. Though it’s interesting to think about “fast open” where a web socket client can enqueue messages before we have confirmation that it’s all going to connect. Should it be#2904sendMessage(RequestBody)
or justsend(RequestBody)
or justmessage(RequestMessage)
? Maybe instead ofsendPing(ByteString)
it should be justping(ByteString)
or evenping()
?
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (12 by maintainers)
Top Results From Across the Web
Websocket vs REST API. 7 Significant Differences - Wallarm
WebSocket protocol, contrary to REST, is stateful while helping two applications in seamless data transmission or information exchange. It's based on port & ......
Read more >Working with WebSocket APIs - Amazon API Gateway
A WebSocket API in API Gateway is a collection of WebSocket routes that are integrated with backend HTTP endpoints, Lambda functions, or other...
Read more >WebSocket vs REST - Key differences and use cases
They're suitable for event-driven apps and services that require high-frequency, low-latency communication between client and server.
Read more >Is AWS ready to provide serverless WebSockets at scale?
WebSockets for API Gateway review Now, with API Gateway, this is no longer necessary. API Gateway handles the connections [and] lets you build ......
Read more >WebSockets for fun and profit - Stack Overflow Blog
The WebSocket protocol is a wonderful tool to build real-time communication apps, but like all tools, it's not a silver bullet. A WebSocket ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For 5: I would like to expose the ping pong api.Because this is very helpful to keep your websocket connected and reconnect when meet with network issue or something else.The WebSocketListener onClose method isn’t reliable in practice.
I propose we always fully buffer WebSocket messages. The consequences:
onMessage()
can return immediately without reading the response body. TheResponseBody
the caller holds is buffered!I’m proposing this behavior even though I know it’s weird. The reason is that message receipts are the application layer’s concern. If the client sends something that’s intended to be durable, the client already needs to hold that thing until a receipt is received. Blocking until the bytes have been written to the socket doesn’t confirm anything.