From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-03-2007 02:22 PM
01-04-2007 09:03 AM
You can dynamically create a DataSocket object per URL and call the Connect method at run time. I posted some code below that shows this. You will need to add error checking to handle bad URLs or failed connections and you will need to make sure that you properly close your connections and dispose them to clean up properly, but this should give you an idea of what to do.
ArrayList connectionList = new ArrayList();
using (StreamReader sr = new StreamReader(urlFilePath))
{
string url;
while ((url = sr.ReadLine()) != null)
{
DataSocket ds = new DataSocket();
ds.Connect(url, AccessMode.ReadAutoUpdate);
connectionList.Add(ds);
}
}
How many connections will your application typically make and what is the rate at which you will need to handle data update events? Before deciding on this approach, you should ensure that it can handle the number of connection and data rates that you need.
01-04-2007 09:47 AM
01-04-2007 11:17 AM
01-04-2007 11:47 AM
01-04-2007 11:57 AM
01-18-2007 04:59 PM
I'd like to add a couple of things.
1) Keep in mind that when you dynamically create data socket objects and listen to the data updated event handler, the callback when data is received is *not* guaranteed to be coming in on the same thread as that on which the data socket was instantiated.
dataUpdatedEventHandler(object sender, DataUpdatedEventArgs e)
{
// this call could be coming in on any thread...
}
2) In terms of keeping track of which data is coming in from where, you can check the URL property on data socket callback. Editing the useful code snippet that was posted earlier:
ArrayList connectionList = new ArrayList();
using (StreamReader sr = new StreamReader(urlFilePath))
{
string url;
while ((url = sr.ReadLine()) != null)
{
DataSocket ds = new DataSocket();
ds.Connect(url, AccessMode.ReadAutoUpdate);
ds.DataUpdated += dataUpdated
connectionList.Add(ds);
}
}
void DataUpdated(object sender, DataUpdatedEventArgs e)
{
(sender as DataSocket).URL <- tells you which item was updated
}