notify client browser about changes on server - client

I am trying to make a simple chat-like application where each of the users share data. I need to somehow update all the clients with the new data in real-time when 1 of them is sending something.
Is there a way to do it, maybe a webserver or smt ? something that works on apache?
For the client page i am using ajax to send data to server and PostgreSQL database to store the datas, but idk how to 'tell' clients that they need to 'refresh' the client browser because 1 client sent new datas to server.
Thank you in advance, Daniel!

I don't know what technology you are using so I would just recommend have a look at this service http://pusher.com/. They are a paid service that gives you the functionality you need. If you give more information on your technology we could provide better help.

Related

where are the chat messages stored in socket.io

Hi,
I was in the middle of developing a PHP chat that stores the messages and user sessions in text files when I learned about socket.io and I would like to switch to this method instead because seems to save CPU usage on my server (currently I have to do GET requests of the php files to load messages and users every 2 seconds).
My question is, are the messages stored somewhere with socket.io? How about the user sessions with their data such as username and profiles? I get all that from a database via PHP as of now and then store it a temporary text session file.
Thanks.
are the messages stored somewhere with socket.io?
No: Socket.io is just a WebSocket library. It's your responsibility as an application developer to use socket.io to receive incoming messages which runs your own code that loads or generates responses and vice-versa. So asking that question is like asking "are the messages stored somewhere with PHP?".
How about the user sessions with their data such as username and profiles?
Again, socket.io is just a library for using WebSockets. It does not have any user or profile management features built-in. It's your responsibility to build or integrate that into your NodeJS code which then uses socket.io
I get all that from a database via PHP as of now and then store it a temporary text session file.
You'll need to keep on doing just that (though you should also store the chat messages in your database too, as using text files won't scale to more than a handful of concurrent users).
Note that unlike PHP websites, NodeJS applications do have semi-persistent, in-memory state (so you can load data from your database and use it in-between requests instead of reloading everything for each new page request or websocket message) but remember that that state will be lost when the NodeJS server shuts-down, crashes, or is killed by your web-host's management infrastructure. Also when you do eventually scale to multiple server instances each one is isolated from each other, so their in-memory state won't be shared. If you absolutely need to share some kind of low-latency (but not in-memory state) then consider using something like memcached or Redis).

How i can share data which i connected with Heroku connect with other salesforce users

I have my website in PHP and DB in MySQL. I want salesforce users to search on my database from within their salesforce. For that, heroku connect seems to be the option. So i am thinking of converting my MySQL DB to PostGre and then use heroku connect to share my data with my salesforce account. The question i have is, how can i share same data with other salesforce users ? Those users are my website clients and i don't want them to go through this process of heroku connect. Is there was of sharing my data with other salesforce users ?
You cannot and should not expose your database directly to your customers. That would allow them to change the data as well as read it.
Your solution here is to create a public API which exposes endpoints that will make it possible for anyone (with proper authentication hopefully) to query your data.
There are many ways you can design an API, whether it's a REST or a GraphQL one. This is something which can absolutely be done in PHP though.

Oracle jet connection with Oracle database without using REST API simple example

I am able to connect to an Oracle database using the REST API, but I want to connect to it without the REST API. Is there any another way to connect to an Oracle database?
The short answer, No.
Oracle JET is a pure client-side toolkit. It does not run or process on the server. Because of that, the only interaction with data resources is via Web Services of some kind. REST is the most common. You could use WebSocket, or Server Sent Events as well, or some other method that a pure client could communicate with.
Do you want to get rid of creating a REST API endpoint in your middleware by hand?
If the answer is yes, then you could use this: http://www.oracle.com/technetwork/developer-tools/rest-data-services/overview/index.html
If the answer is no, then sorry, no. Practically, that is the only way to fetch data from the server.

Intercepting PouchDB communications with CouchDB backend

I am considering PouchDB & CouchDb as an alternative to Amazon Cognito Sync for a hybrid mobile app that will need data synced between devices and users. I have pouchdb working in a small sample app that syncs with a local couchdb.
I need to be able to intercept the communications back and forth between the pouchdb and couchdb in Java in order to do things in response to these sync events. Sort of like Amazon Cognito Sync's sync triggers. Also, I keep thinking much like Spring's AOP around.
Since the couchdb has a rest interface, I thought I could point the pouchdb to my application server which has a controller listening for any request with the db name as the base. When a request, from pouchdb comes in the Java Rest Controller can optionally do something, then forward the request to the real rest endpoint of the couchdb and get a response, then optionally do something again, then return the response to the pouchdb.
Does this seem like a feasible solution? I am currently working on trying to get this concept working. Has anyone else done anything like this? Any major pitfalls to this approach? Currently, I'm using Java 8 with Spring Boot & Jersey.
I think the architecture goes like this:
Data is empty everywhere.
Data changes, the device where the data changed pushes via a REST APIs.
Your server "master", send notification GCM or APN to devices.
In your notification listener, you check the type of notification and you sync the data.
If a new device connects to your "list of devices to sync" you send a push notification to sync the data.
Keep a list of connected devices.
The same ideas goes for every device/web browser. You have a local cache that you push to the "master" if it changes locally.
You will have many cases to deal with, and I don't think there are open source projects that offers the same patter as Cognito Sync.
Also think about scalability, devices don't have to pull your "master", the master sends notification to trigger devices to download the data.
You have to deal with diffs, regular checks, and so on ...
Good luck

Send info to client on server event

I am trying to create a shared calendar as a web app. When someone adds an event on the calendar i want everyone who shared that calendar to see that event too. When someone create an event, I made an ajax that sends the data to a database. Is there a way to send the event from server to other clients that are online on the page and share the same calendar? I did it now by constantly 'refreshing' the info from database.
If anyone has a clue how this can be made, please tell me.
Wanting a web server to "push" information back to the browser is a time old issue. The traditional way to handle this is to have any active clients (i.e. the people still logged into your app with a page open) continuously "poll" the server at a regular interval to see if there's any new information for it. In your case, you can have some JS on the page make an AJAX call every 10 seconds to see if they have any new calendar events they should be aware of. This does increase the overall traffic to your web server so pick your polling time appropriately - otherwise you'll cripple your web server because it will spend all of its time handling these "is there anything new?" requests when most of the time there won't be.
If you want to be a little more cutting edge, you can look at HTML5 websockets. A google search for "html5 websockets tutorial" should give you plenty of resources. They're a bit trickier to use and require that you are running a web server that supports them (you probably are). For browsers that support it, you can maintain a more long term open connection where you can then push data from the web server back to the browser like you want to and your JS will capture "onmessage" events with the updated info. Pointing you at google isn't trying to flake out of a more complete answer, but there's already a number of excellent tutorials out there so look for HTML websockets and you should be able to pull off what you're looking to do.

Resources