How to sync with server data by AngularJS? - angularjs

Angular has two ways data binding which is cool, so I just wonder if it could be sync in Server-Client binding? For example, usually we would request data by $http
$http.get(apiURL)
.then(function(rsp){
console.log('getRsp', rsp);
});
I hope it could send request automatically once server side (inside database for example) changes.
In tranditionally, we can use timeout, but it is kind old way, and watsting resource. What if we can listen the server change? But how?!

You can achiece this by using socket.io. Both on server and client side. By using timeout all of the clients will repeatedly keep on calling the server even if there is no update. With sockets you can keep a channel open between server and client. The server will only notify the client whenever there is a change in the data.
You can find a lot tutorials for sockets on the internet.

Related

How to refresh the website with Nancy if model data changed?

If my model data is changing how to refresh the site automatically to display the changed data?
Is this possible at the server or do I have to write some client code for this?
Thanks for helping.
Michael
You have to write client side code to do this, the server has no relationship with the client once its sent the response - the connection is closed, the server moves on to other requests.
You need to use Javascript to poll the server and update based on server side changes - you can use a data binding framework such as Knock Out, or a larger framework such as Angular to make this easier.
SignalR may help you here, in that its a system which plugs into both the client and server side, keeps open a connection so you can send data to the client side instantly from the server.

How does Firebase's Firebase.on() work?

How does Firebase.on() work? It's suppose to "Listen for data changes at a particular location", according to https://www.firebase.com/docs/web/api/query/on.html
,but how does the client know when to update itself? Is the client also a lightweight server that listens to the Firebase server or does the client automatically do an update every x seconds?
The Firebase client keeps a connection open to the server. Depending on where your app runs, this can either be a web socket or a so-called long-polling connection. Either of these ensures that the server can send new data to the client as soon as it is available.
The client listens for changes on the server and you need to update the client data (your objects) in the event callback.
As a suggestion, this can be greatly simplified with firesync.

Sails server side views and socket for client updates (in angular)

Struggling to get my head around this functionality.
I use a sails server view to host a simple find for a given model in the DB.
When browsing to: url/model I get the html view that populates the data.
So far so good.
My view is handled by angular and have databinding between the visible data and what came from the server (ejs).
Now, I want the data to change dynamically with sockets on the client view.
Reading the code and the docs, it seems I need to have the client view, actually get the data to be able to subscribe to it on the server side. (This handled in blueprints, or manually if I want to in a controller method).
The problem is that I will be querying the data twice in the DB.
Once in the server hosted view with the default HTTP handled blueprint, and then
Twice when I actually have to get the data via sockets.
I managed to only do this once, if my client is standalone, by simply querying the data via sockets only.
But how can I do both ? Server hosted views and data, with subscription to sockets for updates, without having to get the data twice ?
Thx.

Raw socket listening to a REST Channel in Silverlight

I understand how I can use a raw socket to listen to a server application and recieve information but I need an easy to access API and I am very familiar with REST.
Is there a way to push (not by using long pooling) data using a WCF service?
Here's my idea of how things should happen, at least at the begining:
The client accesses a URI with it's access parameters (ip, port, apikey).
The server responses with success/failure.
The server opens a socket for each channel with the client's details.
The server accesses a URI indicating that all channels are now streaming.
But how do I wrap the client or the server socket to access a URI?
Edit:
Maybe I should open a socket that notifies about changes on a channel and on the client side require that it will listen and raise the event accordingly.
This is not a very generic solution isn't it?
You should look into the Net.TCP binding, as described by Tomek (one of the WCF team members) here. You use it more-or-less like you would use the HTTP Duplex binding (i.e., the HTTP Long Poll), but it's much, much faster. It's still more complicated than REST, but it's dramatically easier than sockets, and I don't think you'll find a REST-type solution that does what you need.

GWT Servlet-based Notification (Server Event Bus)

Can anyone think of a good way to allow the server to notify the client based upon server processing? For example, consider the following events:
A user requests a deletion of data, however, due to it's long-running time, we kick it off to a queue.
The client receives a "Yes we completed your transaction successfully".
The server deletes the item and now wants to update any local structures any clients may be using (I'd also like to notify the user).
I know this can be done by client-side polling. Is there a event bus type way to do this? Any suggestions are welcome, but please keep in mind I am using GWT with App Engine.
The standard AJAX interaction is that the client sends requests to the server and expects some sort of response back fairly quickly.
In order for the server to initiate a request to the client, you will need to use WebSockets, and experimental HTML5 feature currently only supported by Chrome.
Or, to simulate this kind of interaction, you can use Comet (long-polling), made available in GWT by the rocket-gwt project.
You want server events for GWT? Have a look at GwtEventService (they couldn't have chosen a better name): http://code.google.com/p/gwteventservice/wiki/StartPage
Of course, it uses a Comet implementation, but you can't do any different when using HTTP, the client always initiates the communication. Request, response.

Resources