# Sending messages to all other app instances

**URL:** <https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737>\
**Category:** Xojo Cloud\
**Created:** [December 29, 2024, 11:42pm UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737 "2024-12-29T23:42:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michelle\_Parker](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Michelle\_Parker](https://forum.xojo.com/u/Michelle_Parker)\
**Post date:** [December 29, 2024, 11:42pm UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/1 "2024-12-29T23:42:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jason\_Parsley](https://forum.xojo.com/user_avatar/forum.xojo.com/jason_parsley/32/152_2.png) [@Jason\_Parsley](https://forum.xojo.com/u/Jason_Parsley)\
**Post date:** [December 30, 2024, 3:18am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/2 "2024-12-30T03:18:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ryan\_Hartz](https://forum.xojo.com/user_avatar/forum.xojo.com/ryan_hartz/32/630_2.png) [@Ryan\_Hartz](https://forum.xojo.com/u/Ryan_Hartz)\
**Post date:** [December 30, 2024, 3:20am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/3 "2024-12-30T03:20:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michelle\_Parker](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Michelle\_Parker](https://forum.xojo.com/u/Michelle_Parker)\
**Post date:** [December 30, 2024, 3:21am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/4 "2024-12-30T03:21:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michelle\_Parker](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Michelle\_Parker](https://forum.xojo.com/u/Michelle_Parker)\
**Post date:** [December 30, 2024, 3:39am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/5 "2024-12-30T03:39:33Z")

</div>

Hi Ryan

Thanks! I’ll look at that example project.

---

<div class="post-metadata">

**Author:** ![Hanif\_Saad](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/a4c791/32.png) [@Hanif\_Saad](https://forum.xojo.com/u/Hanif_Saad)\
**Post date:** [December 30, 2024, 5:15am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/6 "2024-12-30T05:15:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [December 30, 2024, 5:46am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/7 "2024-12-30T05:46:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Patrick\_Salo](https://forum.xojo.com/user_avatar/forum.xojo.com/patrick_salo/32/514_2.png) [@Patrick\_Salo](https://forum.xojo.com/u/Patrick_Salo)\
**Post date:** [December 30, 2024, 6:50am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/8 "2024-12-30T06:50:17Z")

</div>

@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):

> [@Sending a message to active sessions](https://forum.xojo.com/t/sending-a-message-to-active-sessions/76692/3):
>
> As for the first problem, you could make your admin function write a file to disc, let’s say a json string which contains the reason and the time when the update will be applied. Then add a Timer to the App class which looks for the file once a minute. If it finds it, it notifies all of the users that the app is going down, why and when. In app.opening you delete the file if it exists.

[Original Reply](https://forum.xojo.com/t/sending-a-message-to-active-sessions/76692/3)

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

---

<div class="post-metadata">

**Author:** ![Michelle\_Parker](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/a88e57/32.png) [@Michelle\_Parker](https://forum.xojo.com/u/Michelle_Parker)\
**Post date:** [December 30, 2024, 6:54am UTC](https://forum.xojo.com/t/sending-messages-to-all-other-app-instances/83737/9 "2024-12-30T06:54:41Z")

</div>

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.
