2

I want to write an application that "listens" for a server push.. i.e the server can broadcast.. I want to do this via an open web request to a php page that holds a database vale in it and returns the database value.. so that if the database changes.. the value changes which means C# app knows to fire a initiation of some sort (in my case it's a "refresh" request) 99.99% of this work is done via this refresh request.. I only need to know.. ho w to implement the "trigger" or "event" from the server... the standard methodology for this (I know) is polling x seconds but I know that a proper event driven architecture is much nice..

Remember this is nothing to do with IIS ... This is a windows client C# exe that needs to "listen" to a web server.. are there any good code examples people know about?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
conners
  • 1,420
  • 4
  • 18
  • 28
  • this is for Visual Studio 2010 - I have nothing against Windows 8 / VS 2012 it's just no-one has Windows 8 yet – conners Oct 28 '12 at 09:03

1 Answers1

1

HTTP is a request/response protocol - there is no "push". Common historic approaches to solve that are frequent polling and long-polling, but these days web-sockets are another option. You can use web-sockets from a client application: in .net 4.5 on Windows 8 / Server 8 there is an inbuilt client in the framework, but it isn't hard to write one based on raw TCP from the specification (or just look for an existing client library). Web-sockets supports bi-directional communications, so the server can spontaneously broadcast to the clients. Great for prompt updates.

You would of course also need a web-socket server implementation, but that is available for most platforms and toolsets.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • thanks for the advice, you say it's not doable, but that is not the case since http connections can remain open for "x" length, then postback right afterwards as an asynchronous event after watching the readystate, it is done in JQuery all the time. As to the other matter, writing a web socket is a port listener and that is not possible behind the majority of firewalls, and (often sadly) even ISP's.. – conners Oct 29 '12 at 01:02
  • Marc it seems you were right, these two projects (client) https://github.com/sta/websocket-sharp (apache server) http://code.google.com/p/phpwebsocket/ are both sides of the coin, because the client initiates firewalls will fulfil it – conners Oct 29 '12 at 01:13
  • However this is not my question: this is a post about how a thing called "comet" works from BROWSERCLIENT to server, I need c#WINDOWSCLIENT to server.. http://stackoverflow.com/questions/5169717/how-does-facebook-chat-work "Reverse Ajax" – conners Oct 29 '12 at 01:21
  • COMMENT: this guy did the same thing. http://stackoverflow.com/questions/3742631/c-sharp-httpwebresponse-comet-problem – conners Oct 29 '12 at 01:32
  • @conners "comet" is an umbrella term; the main technique used in "comet" is "long-polling"... which I mentioned. The fact that it is a windows client is irrelevant here. And I maintain: even from a windows client, the most appropriate technology here is web-sockets. Long-polling etc is a hack - abusing a protocol to make something work. Web-sockets is *designed* to fully support ad-hoc bidirectional communication, meaning: the server can send data to the client at any time, unrelated to a request – Marc Gravell Oct 29 '12 at 06:59