How does meteor update the browser? - meteor

Having watched Meteor Framework screencast. I noticed that changing the database seamlessly changes the data in browser. Usually AJAX, just reloads a part of page every few seconds but here I didn't noticed browser reloading. How did they achieve that in Meteor? Is it Node.js dependent?
UPDATE: Toby Catlin poses another interesting question. How does Meteor handle different browsers?

They use both Session and Meteor.autosubscribe (from Meteor API) to ensure that changes are reflected on the clients.
These Meteor APIs use XHR (XMLHttpRequest) by SockJS. SockJS is WebSocket emulation utility. So when something changes on the server, SockJS ensures that an XHR is sent, and the changed data is in the JSON response.
Yes, Meteor is fully dependent on Node.js. From the Meteor docs:
A Meteor application is a mix of JavaScript that runs inside a client web browser, JavaScript that runs on the Meteor server inside a Node.js container, and all the supporting HTML fragments, CSS rules, and static assets. Meteor automates the packaging and transmission of these different components. And, it is quite flexible about how you choose to structure those components in your file tree.
The only server asset is JavaScript. Meteor gathers all your JavaScript files, excluding anything under the client and public subdirectories, and loads them into a Node.js server instance inside a fiber. In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.
Sources: http://docs.meteor.com/ and https://github.com/meteor/meteor

There are a few techniques that allow the server to push data into the browser without the browser needing to request it. The term for such technology is Comet [wikipedia.org] and most techniques are related to AJAX (there was a bleach called Comet and a cleaning product called Ajax). There are a number of connection types: long polling, streaming XHR, forever frame, server-send-events and websockets. Socket.IO is a nice library that provides connection types to streaming servers.
You do need a server that will support Comet connections. You can google for current ones but off the top of my head: node.js, tornado, cometd, orbited, Jetty streaming
I would guess that Metor would use different connection types depending of the capabilities of the browser, eg websocket for Chrome and long polling for IE. If anyone can give a more specific answer i would be interested

Related

Implementing callback from DB layer into App layer

I have a Java Servlet which writes a message to the database. Some other tier picks up this message from the DB and processes it and updates the status of this message in the database. Meanwhile in the servlet, I have to keep polling the database to get an update on status of the message which was written earlier.
How can I implement a Callback instead of polls so that unnecessary database queries are avoided?
I suppose you're talking about server push technologies. I suggest you to use HTML5 websockets for this. Use your same servlet with a websocket to communicate between both ends.
There are so many examples out there.
Java WebSockets - In this example he uses jetty, but you can
use jboss or tomcat for this.
StackOverFlow post describe the same.
pushing data for multiple clients from a server via websockets
try above links and it is worth for trying.

Interactive HTTP server

For manually testing an HTTP client in my application, I'd like to use a tool which starts an HTTP server my application can connect to and that lets me respond to request from my application manually. I'm basically looking for a tool with a GUI that lists all incoming requests and allows me to select a status code and type a response message. I've already tested the functionality with unit tests but I also want to verify it manually with no mocking etc.
Sounds simple but I didn't find such a tool. I've found some that can be scripted but no interactive one. Do you know one?
This can probably be written relatively easily by creating the Swing GUI dialog popup inside the servlet servicing methods. Have never seen Tomcat running this way but probably it would. Only, mind the server time out. It may be not long enough for you to make an input and require to be configured, also on the client side. Also, parallel calls will make multiple popups that may be difficult to respond but probably this is a single client app.
As a simplest solution, server GUI can be simply disposed after call and newly created as the next call arrives. This will make eveything indepenent on how servlet container is managing the servlets (does it stays, is it destroyed, maybe class is unloaded, who knows). Advanced solution could include the "server servlet" that would interact through its own JSP page but then it may be complex to update it when the new call arrives (unless maybe refresh periodically).

Platform Agnostic Way to Tell if Meteor is Running

Question says it all really. I can setup a page at a known location, and make sure the http request works, but that feels kinda hackey.
Meteor.status() is a client side function which will help for individual clients within the Meteor context. Your best bet for a platform-agnostic check is a DDP client that lives outside your Meteor environment. (True, the Meteor folks proposed the DDP client, but the intention is that it serve as a protocol for real-time platform, not a tightly coupled part of the Meteor architecture).
In practice, then, you'd need to wire up a DDP client and subscribe to a server-side publication, returning whatever defines 'running' in the context you require. This could be simply a collection of mongo documents, or some status checks based on more complex set and unset method calls within your publish function.
Here are a couple DDP clients I've found
DDPClient.NET
node-ddp-client
ruby-ddp-client
Hope that helps.

asp.net-async pages (comet/reverse ajax/server push)

I am trying to develop a comet page using Asp.net. Surfed a lot and found some plugins like Pokein. I feel this blog, to be best suited for my project as it goes in hand with jQuery. But this is in MVC. I wonder if i can do the same with ASP.NET website pages. All i need to do is to free up the worker process during the long waiting ajax-call duration. In MVC, async controllers come handy. Could someone help me if I can do the same with website pages(say: free up the worker process during the long waiting jquery Ajax call inside the static web method). I read about async pages in websites here, but this will take a full posback and the page is blocked during the long wait. (basically free up worker process during pre-render and wait for long polling, but the UI still keeps refreshing as the page life cycle is not completed)
Thanks in advance for your advice geeks...
'Push' style architectures on the web using purely ASP.NET, JavaScript, JQuery, AJAX etc. can be difficult and involved to implement. Normally the route most go is more of a glorified 'pull' model where a timer somewhere client side will check back to the server for the needed data or state required and then preform the necessary action. If you truly want a more of a push architecture with purely web technologies, you will want to look into the long polling 'Comet' architecture. You can read more about it below:
Comet (programming):
http://en.wikipedia.org/wiki/Comet_(programming))
Ideally in the Microsoft world if possible you could jump over to a rich client technology like Silverlight to work with a duplex polling WCF service in which a client subscribed to the server can get updates pushed from the server back to the client. Anytime (as of today)I would need to implement any type of 'push' architecture today I would personally opt for Silverlight as there are numerous examples on how to implement this easily. If you are interested take a look to the (2) links below:
Pushing Data to a Silverlight Client with a WCF Duplex Service:
http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx
How to: Build a Duplex Service for a Silverlight Client:
http://msdn.microsoft.com/en-us/library/cc645027(VS.95).aspx
Regardless, COMET/Silverlight/Flash, etc. are probably not going to be a widely used option going forward anyways with web sockets in HTML5. But since the spec is not quite ready (see: http://ishtml5readyyet.com/) you might needs to look at using a Silverlight control on your ASP.NET page in the meantime and it will work well.

Asynchronous web service call in ASP.NET/C#

We have an application that hits a web service successfully, and the data returned updates our DB. What I'm trying to do is allow the user to continue using other parts of our web app while the web service processes their request and returns the necessary data.
Is this asynchronous processing? I've seen some console app samples on the msdn site, but considering this is a web form using a browser I'm not sure those samples apply. What if the user closes the browser window mid request? Currently we're using the Message Queue which "waits" for the web service to respond then handles the DB update, but we'd really like to get rid of that.
I'm (obviously) new to async requests and could use some help figuring this out. Does anyone have some code samples or pertinent articles I could check out?
Yes, what you're describing is async processing.
The best solution depends to some degree on the nature of the web services call and how you want to handle the results. A few tips that might help:
One approach is to send a request from the initial web request to a background thread. This works best if your users don't need to see the results of the call as soon as it completes.
Another approach is to have your server-side code make an async web services call. This is the way to go if your users do need to see the results. The advantage of an async call on the server side is that it doesn't tie up an ASP.NET worker thread waiting for results (which can seriously impair scalability)
Your server-side code can be structured either as a web page (*.aspx) or a WCF service, depending on what you want to have it return. Both forms support async.
From the client, you can use an async XMLHTTP request (Ajax). That way, you will receive a notification event when the call completes.
Another approach for long-running tasks is to write them to a persistent queue using Service Broker. This works best for things that you'd like users to be able to start and then walk away from and see the results later, with an assurance that the task will be completed.
In case it helps, I cover each of these techniques in detail in my book, along with code examples: Ultra-Fast ASP.NET.
If you're not blocking for a method return you're doing asychronous processing. Have a look at Dino Esposito's article on using AJAX for server task checking.
You can perform asynchronous web service calls using both Web Service Enhancements (WSE) and Windows Communication Foundation (WCF) in your C# code. WSE is discontinued, so its use is not recommended. Generically speaking, if you were to terminate program execution in the middle of an asynchronous call before the response returned, nothing bad would happen; the client would simply not process the result, but the web service would still be able to perform its processing to completion.
If your client web application is responsible for updating the DB, then without anything else in your client code, quitting in the middle of an asynchronous operation would mean that the DB was not updated. However, you could add some code to your client application that prevented the browser from quitting entirely while it is waiting for an asynchronous response while preventing new web service calls from being run after Close is called (using Javascript).
You have 2 distinct communications here: (1) from web browser to web application and (2) from web application to web service.
diagram http://img697.imageshack.us/img697/6713/diagramo.png
There is no point of making (2) asynchronous: you still would have to wait for web service to finish processing request. If you end HTTP request from browser to web application the client would have no clue what the result of request was.
It is much better to make asynchronous request from web browser to your web application. Ajax is ideal for that. In fact, that's what it was created for. Here's couple of links to get you started:
jQuery Ajax
ASP.NET AJAX

Resources