Question

Basically, I have a need for a c# server to be able to send data back to an HTML5 webpage which has previously send data to the server. The server is retrieving data from another application and this data then needs to be send to the webpage to be displayed.

This c# server is running on .NET CF 3.5 so websockets are not an option (not supported).

I have seen some suggestions elsewhere but nothing which fits the necessary criteria for this particular situation. Most other implementations seem to work on the basis that the webpage will only be waiting for this data to be sent over.

Any and all suggestions welcome!

Was it helpful?

Solution

If websockets are not an option then you are left with Comet.

Client-side you could do something like this :

(function poll(){
    $.ajax({ 
        url: "url",
        success: function(data) { /*display data*/ },
        complete: poll, 
        timeout: 30000 });
})();

Which means an ajax request will be sent every 30 seconds.

This is not as performant as websockets but it works quite well.

OTHER TIPS

  1. Create an .aspx page and remove all the HTML from it. Call it GetData.aspx
  2. In the code behind of GetData.aspx.cs you can receive the POST data from the HTML5 page.
  3. Do work.

  4. Use jquery.

  5. $.post("GetData.aspx",{name: value},function(json){ // put processing instructions here. });

There are two ways to do this :

Using a ASP.NET web-page

  1. Create HTML element that calls a javascript function
  2. Inside of the javascript function, use ajax to make a POST to a ASP.NET Web Page (that uses C# as back-end)
  3. Get the returned value in the ajax "success" block.
  4. Use as you wish...

Using a jSON string return

  1. Create HTML element that calls a javascript function
  2. Inside of the javascript function, use ajax to make a POST to a Web Service (that uses C# as back-end), that returns a jSON string.
  3. Use the returned jSON data in which ever way needed.

I personally prefer jSON, as it emulates a data set, and works well with HTML and ajax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top