websocket send frame from non suspending progress listener
See original GitHub issueHello. I’m facing problem with webockets. I want to send frame each time my “manager” calls listener with progress.
webSocket("/blockChainSyncProgress") {
manager.addBlockChainProgressListener { progress ->
launch {
outgoing.send(Frame.Text("$progress"))
}
}
}
since the .addBlockChainProgressListener is not suspending function, websocket will close after the listener is added.
I can add while (isActive) delay(1000)
so the function looks like:
webSocket("/blockChainSyncProgress") {
manager.addBlockChainProgressListener { progress ->
launch {
outgoing.send(Frame.Text("$progress"))
}
}
while (isActive) delay(1000)
}
but I’m not sure if it’s the recommended way of doing that.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Sending and receiving frames over the same websocket ...
The problem is that when i use recv() while the data sending has already begun the server stops sending data and only waits...
Read more >Using Pusher WebSockets To Show Progress During Page ...
Ben Nadel explores the use of Pusher WebSockets to indicate progress during the page unload / redirect experience in Lucee CFML 5.3.7.47.
Read more >WebSocket.send() - Web APIs - MDN Web Docs - Mozilla
The WebSocket.send() method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value ...
Read more >A Simple Multi-Client WebSocket Server - Forty Years of Code
Learn from this simple websocket server with realistic features. ... such as streaming video many never send an end-of-message frame.
Read more >python-websockets(1) - Arch manual pages
#!/usr/bin/env python import asyncio import websockets async def echo(websocket): async for message in websocket: await websocket.send(message) async def ...
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
Also note that it looks like you are not unsubscribing: is that ok in your particular case? Shouldn’t you remove listener once a client get disconnected?
The other alternative is to use a global instance of BroadcastConflatedChannel to publush manager’s current state and subscribe client’s session. Unfortunately this API is still experimental