Pushing From Server To Client

Is there a way for the server to update the client without the client polling the server?

I’ve not thought his through particularly, but I might was some sub-1 second updates from server change to display, and have the feeling that if i had several clients attached then timer polling might be an issue.

Actually, that’s the real question - is having for example a 200ms poll running on (say) 10 (or 100) attached clients going to be an issue? I mean it works but would you guys see an issue with that?

I have 2 apps in mind - one is a system monitor showing real time calls and their progress (my day job) and the other is a multiplayer game (my evening job).

8 Likes

Not yet! We want to make sure this can be done in a scalable manner. But yes, it’s on our list :slight_smile:

For the time being, I’d suggest polling with a Timer component.

2 Likes

I’m a software engineer of 20+years, and fully web-enabled, and the lack of any effective way for the server to initiate and send data to one/all clients is what is (unfortunately) making me walk away from Anvil right now. consider me a lost paying client because of this. :slight_smile: Your entire ecosystem is based on websockets, which excel at this, and yet there’s no apparent way for me to send, or steam a sequence of send/s from an anvil-uplink ( specifically from a persistent anvil background_task in my case ). If I’m wrong, great, maybe a link to a simple example where a background_task send/s a 1Hz ‘heartbeat’ or timestamp or simething to all connected clients is the sort of thing i went looking for and failed to find… although i would be sending hundreds of small messages a second, to all clients, in my particular case.

3 Likes

Any progress on this? I could really use this.
Polling frequently from several clients is not very scalable either.
I can imagine that pushing a lot of data from the server to the client would be a problem. Just a “signal” to the client that something has happened would very useful.

3 Likes

MQTT might be a workaround: I implemented some MQTT sample code

1 Like

Any update regarding the issue, websocket is exact tool for pushing from server to client. Using timer checking even every 10 seconds doesnt work well when many users use the app and kind iof wasting server resource.

Any movement? On this issue?

I’ve used the cache update functionality of portable classes for this in one or two places. I tworks well but only within a single session:

1 Like

Thank you, attempted to implement this and discovered what you just explained “only within a single session”. My end goal is to make the application real-time as I will have multiple user’s interacting with each other, but I was attempting to avoid another service (MQTT method) to minimize cost.

Do you have insight on how much constant polling can drag down your server, at scale?

You should be able to write your own real-time messaging system in Anvil. While the Anvil server isn’t suitable for this, since it isn’t persistent, Anvil Uplink servers are persistent. You could register clients with an Uplink, and the server could call an Uplink function to send messages to the clients.

Your Uplink would need to send a message to all registered clients, probably through a socket connection. Clients would need to be listening on a socket connection via Javascript. That part will likely be painful, but if you need real-time without polling, it should be doable.

All that’s totally untested, since I don’t use Uplink myself. Other people may very well have tried this and run into issues. It also may be so much work to get right that using a third-party service seems like a good deal.

You’d also have to host the Uplink somewhere, and work through the issues with Uplink disconnects, etc. At that point you might be better off hosting an open source MQTT broker the same place you’d have hosted the Uplink.

1 Like