views:

479

answers:

5

I have a client-server application - wherein the server is essentially an ASP .NET web application and the distributed clients are desktop applications.

The clients need to receive some data from the server - when there is new data for the client. Right now, the way this is done is - the client keeps querying a web service every x minutes 9say 2 minutes) and keeps checking if there's new data for the client.

Ideally, the way it should work is that the desktop app should receive updates as and when they are available, it need not pull from the server; instead the server should be able to push to the client.

How do I go about doing this - given the architecture of the solution - a web application needs to push data to desktop applications (clients) in the same network (a LAN)?

A: 

If you can leave a socket open, the client can connect to the server and the server can just push data down the socket when appropriate. There is no reason why the side that initiates the connection must always be the one to initiate the data transfer.

lambacck
This app is for general intranets in industries. Using socket connections - i.e. using a socket would need a port to be opened for access - reconfiguration of the firewall etc etc. Is this a reasonable installation pre-requisite or will industrial clients generally oppose to this?
SaM
An HTTP connection _is_ a socket. What the answer is (correctly) recommending is that the client send a GET, but the server delay sending back a response until it has data ready to send.
Jens Alfke
Yes, but HTTP connection is on port 80, which isn't blocked by firewalls? What you described sounds perfect - server deferring response until it has data - how to go about doing this?
SaM
"Yes, but HTTP connection is on port 80, which isn't blocked by firewalls?" If port 80 is blocked then you do not have a working internet/intranet connection if http is working use whatever port it has been configured to use.
SDX2000
+2  A: 

You could use WCF callbacks - this are a web service where you can subscribe to notifications from a client and the server will send messages to subscribed clients. I have a beginners guide on my blog.

blowdart
WCF? So more than just .NET 2.0? Sadly, .NET 2.0 is a limitation I need to work under? Will WCF callbacks help in that case?
SaM
Nope, afraid not, it's WCF only I'm afraid.
blowdart
+1  A: 

You may be interested in the SO question. What you are describing sounds like a Comet application - server push to a client.

David Robbins
+7  A: 

What you're describing is "server push", which these days is often called "COMET". Using those keywords in a web search should turn up a lot of useful information.

The most common technique for this is called a "hanging GET". The client sends a GET request to a specific URL, and the server accepts the connection but delays sending a response until it has data to send. When the client receives the response it sends another GET so it's ready for another message.

Jens Alfke
Just wanted to drop a note that you can use the IHttpAsyncHandler ( http://msdn.microsoft.com/en-us/magazine/cc164128.aspx ) and System.Threading.Monitor to easily build a (sort of) event driven "server push" in .NET 2.0If anyone knows of a full-blown utility class for this, please post some links
Radu094
A: 

Check out WebSync; it's a Comet solution for ASP.NET/IIS, but there's also a full .NET client available, which enables integration with thick clients, windows services, etc. So it sounds like it should fit the bill pretty nicely.

jvenema