I would like to know how I can send a simple notification to users on a local network, send a notification to all other devices with the app connected to the PostgreSQL database ...
I would like to know how I can send a simple notification to users on a local network, send a notification to all other devices with the app connected to the PostgreSQL database ...
In PostgreSQL (Versao >= 9.1)
you can make use of LISTEN
/ NOTIFY
to do something like this.
These functions allow clients connected to the bank to receive asynchronous notifications through a specific channel.
For example, clients connected to the database listening to the foobar
channel will be able to receive the notifications:
LISTEN foobar;
To notify customers who are listening on channel foobar
:
NOTIFY foobar, 'Oi, eu sou uma notificacao!';
If you want a particular client to no longer listen the notification channel foobar
:
UNLISTEN foobar;
Reference:
I hope I have helped!