views:

30

answers:

2

Hi there,

i have a desktop application and a browser with a started web-application running on my computer. If i select something in the desktop application i want to let the web application execute some JavaScript.

My question is now, is there a possibility to communicate directly between this 'applications' or is the only way to notify the web-apps server, and the web-application polls after this changes with ajax or something else?

do you have some links to read or some keywords to use with Google?

thx in advance

A: 

Your browser is not a web server, and must therefore initiate all web communication. I'm going to guess that your desktop application is a web client only, and not a web server. Therefore it must initiate all web communication. Your web application is a web server, and therefore does not have to initiate communication. With respect to the browser or the desktop application it cannot initiate communication because neither of them are web servers.

Therefore, if you wish to have the desktop application communicate with the web browser, you must use the web application as the intermediary, and the web application must store any messages shared between the browser and the desktop application, and the receiver of the communication must poll the web server for any new shared data.

Jay Godse
+1  A: 

The web app can easily access the desktop app via plain old HTTP. Roll a primitive HTTP server into your desktop app, let it listen on some high port, let the Web app issue an AJAX-style HTTP query to localhost:thatport (did I mention jQuery yet?).

But you want the info to go the other way around - desktop to web. Despair not, there's a little something called polling. The web app issues a request. The HTTP server within the desktop app catches it and does not respond for some reasonable time-out (like, 10 seconds). If an event happens in the desktop app during that time, you respond right away with the event data. If not, you respond, once the time-out expires, with a code that says "keep waiting", and the web app reissues the request. If the event that needs to be passed happens in between the HTTP requests, it's queued until the next request comes.

This technique is enabled by the fact that AJAX is asynchronous - a pending HTTP request does not interfere with browser's normal functionality.

Seva Alekseyev