Sending messages to all other app instances

I’m looking sending a message from a web app instance to all the sessions on the other web app instances on XojoCloud.

I am using EasyTCPSocket and I have a method to send the messages, but how do I contact all the other app instances on Xojo Cloud?

Hi Michelle - There’s no built-in way to do this so I would probably store the messages in a SQLite database (stored in the Shared Documents folder) and then have your code check that database for new messages.

1 Like

There’s an example project in the Web folder (I think… not at the computer). It’s called something like Communicate with All Sessions. I use something like this in my XC web app when I’m about to push through an update. It sends all users logged in a message that there will be an update in about an hour and to save work and log out prior to then

2 Likes

Hi Jason

Thanks for your answer. I do have the info stored in a database, but I need to notify all users immediately, even if they are editing another record, so I don’t want to poll the db.

Hi Ryan

Thanks! I’ll look at that example project.

I am not sure if its workable that way.

The example provided shows how to notify users from all sessions connected to a single web app instance.

Michelle is asking to notify all users from all sessions in multiple web app instances ( eg in Xojo Cloud usually have more than one instances of the same app depending on the number of the cloud’s virtual CPUs)

Using the SQLite approach is good but all web app instances would have to pool the database from time to time for notification.

A faster way would be for each of the web app instances to log their ports ( eg: 8001, 8002, 8003, 8004) in the database and the initiating ( one that wants to make notification) web app ( eg: one running in 8002) would issue an http call to other instances ( 8001,8003,8004 obtained from the ports stored in the database) to initiate the notification plus doing the notification for itself internally.

2 Likes

Nothing is preventing you from opening more database connections. You can have one global connection that is not used by any session to do the polling. Once it sees the message, it does what it needs to with the sessions in its own instance.

If you’re using PostgreSQL, you could also use its notification system to achieve the same effect.

2 Likes

@Greg_O Had a solution a year or so ago that you might be able to adapt, depending upon your situation (second paragraph of his reply):

Original Reply

The essence being that instead of pushing a message to the active sessions, they regularly check in and poll/pull updates.

2 Likes

Thanks everyone!

I had already logged the ports to the database, so using Httpsocket to send a simple request to the other ports seems to work well.

Just to clarify, the updates aren’t very often, but they have to be instant, so this seems fine for now.

2 Likes