ASP.NET - Utilizing Comet to send server messages to multiple clients

I am developing an application that relies on server-side variables which update every second. It is crucial that all clients viewing the webpage are able to see these updates in real-time.

Many people have suggested using comet as it allows for pushing/pulling of data every second. However, I have a few questions regarding this:

  • In terms of efficiency and accuracy, would it be better to pull the new data from the client or push it from the server, considering the need for updates every second?

  • Additionally, the item IDs on the server side (along with their corresponding variables) can change. When a client refreshes the page, they should still receive the most up-to-date and relevant IDs. What is the best way to implement this using jQuery/JavaScript on the client side?

  • Lastly, I am having trouble finding a reliable (and affordable) comet library/api for ASP.NET (C#). Has anyone had success using a comet library with similar requirements? We anticipate having up to 2000 comet connections active at any given time.

Answer №1

One of the standout features of the PokeIn ASP.NET ajax library is its SendToAll function, which allows for easy communication with multiple clients.

Answer №2

WebSync from Frozen Mountain is a powerful comet server designed for IIS and ASP.NET, offering seamless integration into your application stack to enable real-time data communication with a large number of clients per server node.

Make sure to explore the Community edition which is available for free!

Answer №3

What is the most efficient solution for constantly updating data every second: pulling from the client or pushing from the server?

In my opinion, it doesn't matter too much as the time intervals are short between data requests and updates. I would suggest initiating a new XMLHttpRequest on the client side after each successful request. You could also consider sending the server the latest received data so it can compare with the current one and only respond when there is new data available.

I am facing an issue where item IDs on the server can change, and upon page refresh, the client needs to retrieve the oldest and currently active IDs. How can I ensure that my jQuery/JavaScript on the client side keeps track of these changing IDs?

If I understand correctly, you could store all name/value pairs in an object on the client side. When new variables are received, they won't overwrite existing data but rather update it with the latest values. It could be structured like this:

{ first_variable: 345,
  second_one: "foo",
  and_the_third: ["I", "am", "an", "array,", "hooray!"]
}

When a new value for `second_one` arrives, such as `"bar"`, the object would update like so:

{ first_variable: 345,
  second_one: "bar",
  and_the_third: ["I", "am", "an", "array,", "hooray!"]
}

I am struggling to find a good, affordable comet library/API for ASP.NET (C#). Has anyone had success using a comet library with C#?

While I lack experience with ASP.NET, have you considered writing your own server-side code to maintain an open connection and periodically check for state changes? This approach might eliminate the need for a specific library.


UPDATE: To demonstrate how to maintain an open connection on the server side, here is a PHP long-polling simulation I created:

<?php
  sleep(5);
?>
<b>OK!</b>

Rather than having the process sleep, you can continuously monitor for state changes in a loop. Additionally, instead of returning HTML elements, you can send back data, potentially in JSON format. Adapting this concept to ASP.NET/C# should not be overly complex.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Number each element in sequence

Looking to give sequential numbering to elements by iterating through them. For instance, if there are 6 input elements, the goal is to update their names correspondingly like "name=input1", "name=input2", and so on. This involves using a for loop to reas ...

What steps can be taken to ensure that a JavaScript webpack module created for the browser can be safely loaded in a node environment?

I'm currently in the process of modernizing an old JavaScript framework I created, aiming to upgrade it to ES6/module standards. However, I am encountering quite a few challenges along the way. One of the issues I'm facing is related to server-s ...

It appears that using JQuery's .when and .done functions may result in the code executing before the script has finished loading

Since updating the hard-coded <script> with JQuery promises, I have been encountering these errors frequently: https://i.stack.imgur.com/xkWAk.png The issue seems to be inconsistent in replicating. Sometimes, the error occurs while loading the page ...

CrossBrowser - Obtain CSS color information

I'm attempting to retrieve the background color of an element: var bgcolor = $('.myclass').first().css('background-color') and then convert it to hex function rgbhex(color) { return "#" + $.map(color.match(/\b(\d+ ...

How to Retrieve a Date using Month, Week, and Day Numbers in JavaScript

Could anyone assist me in extracting the date (yyyy-MM-dd) from the following parameters: year : 2021 month : 2 (February) week : 1 (1st week of February) day : 1 (Monday) Any suggestions or ideas would be greatly appreciated! Thank you! :) ...

Using Axios to Send a JSON Object with Nested Properties

Utilizing the Axios Http Client on my website poses a challenge when it comes to obtaining the user's location through the browser's geolocation feature. Once the location is acquired, I aim to send this data along with other information. To acco ...

Encountered an issue while executing the next build process

Every time I run npm next build, it throws an error message. Despite my efforts to search for a solution online and installing the "extract-text-webpack-plugin," the issue persists. The error being thrown is as follows: > next build (node:8136) Depre ...

Utilizing jQuery to access Flash functions

When trying to access functions in my SWF using jQuery code, I encounter a compatibility issue with Internet Explorer. The code works fine in all other browsers except for IE. As jQuery is supposed to provide cross-browser functionality, writing addition ...

The server nodejs is unable to recognize the dotenv file

This is my very first project with the MERN stack and I'm currently working on pushing it to GitHub. Since I am using Mongoose, I needed to protect the login credentials for my account. After some research, I discovered the solution of using a .env fi ...

Identifying Equivalent Connections

Currently, I have a collection of link URLs obtained from a recent web crawl. As I delve into developing a visualization/path finding suite, I've encountered an issue with the dataset. Due to the fact that the website I crawled was created by humans, ...

Troubleshooting Problem with JQuery Paginate Plugin Alignment

I have implemented jquery ui 1.10.4 on a web application to paginate and display a specific number of items from an ArrayList on a webpage. However, I am facing an issue where the pagination buttons do not adjust their position when the size of the list ch ...

Problems with radio button serialization in jQuery form plugin

I've created a basic form: <form class="dataform" method="post" id="settings" action="/"> <input type="radio" name="shareSetting" value="n"/> <input type="radio" name="shareSetting" value="y"/> <input type="button" na ...

The query string in web forms consistently returns a null value

When using the Facebook share feature to share image URLs, I am facing an issue where the user is not redirected back to the same page upon clicking the shared image on Facebook. In my backend logic, there is a process that needs to be completed on the Im ...

Steps for deactivating a button until the form has been submitted

Click here for the Fiddle and code sample: $(".addtowatchlistform").submit(function(e) { var data = $(this).serialize(); var url = $(this).attr("action"); var form = $(this); // Additional line $.post(url, data, function(data) { try { ...

How come I am unable to access a local JSON file using AngularJS $http?

I've been attempting to load a local file (todo.json) located in the same directory as my webpage using the following line of code: $http.get("todo.json").success( function( data ){ //Do Some logic}); However, when I try to do so, I encounter the fo ...

Is there a way to track the number of visits by a 'user' to a website?

Looking to hide certain parts of my website from users who have visited more than a specified number of times. The NY Times site has something similar. Utilizing react & firebase for this project. Considered using IP addresses, but it seems to identify l ...

Is it necessary for a writable stream in NodeJS to wait for the drain event before writing again automatically?

Below is the code I am working with: const { Writable } = require('stream') let writable = new Writable({ highWaterMark: 10 }) writable._write = (chunk, encoding, cb) => { process.stdout.write(chunk) } function writeData(iterations, writ ...

Managing authentication tokens in next.js

I'm currently working on a next.js app that requires authorization for certain functionalities. In the past with CRA, I would store the token in a config.js file and easily import, use, and update it throughout my application. Here is an example of ho ...

Prevent TypeScript from generalizing string literals as types

I have a constant Object called STUDY_TAGS with specific properties const STUDY_TAGS ={ InstanceAvailability: { tag: "00080056", type: "optional", vr: "string" }, ModalitiesinStudy: { tag: "00080061", type: " ...