LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

pointers on setting up datasocket connections

I have a datasocket server, and a number of datasocket clients. I have two structures which need to be shared : a) astrLoggedin which has elements char szIPAdress[], int iNumChannels, int iAgents and b) astrCampaign which has char szIPAddress, and char szCampaignName[]. Each of those structures need to be arrays. When a new client PC comes on line, I need to add an element to the astrLoggedin array. Can you give me a general outline of what I need to do to set this up, including what I need to do in the DataSocket Server Manager setup, and what kind of callback I will get when a new client comes up. What code do I need to run in the client to inform the server that it has been added? Thanks, Woolie
0 Kudos
Message 1 of 4
(3,229 Views)
I'm not quite sure if you understand the client/server relationship in DataSocket correctly, but I will just rehash it to clarify what I mean in my answers to your questions. With DataSocket you only create applications that are clients, the server is just a communication hub that manages sockets in which multiple clients can share data.

So what you should do to see when a connection is successful, is in each respective client handle their DS_EVENT_STATUSUPDATED event inside of its DataSocket callback function. You shouldn't really need to check to see from each of the clients whether another client is online.

If you want to do something of that fashion you can set up a specific DataSocket that is designated to hold a value that will show if a client(s) is online or not, note though that DataSocket is a "data sharing" protocol and is not really intended to provide all of the connection management attributes you get with TCP/IP. If you need more control of things like this than I highly suggest using TCP/IP in CVI instead, so that you can write a server yourself that can keep track of host names that connect to it, just take a look at the examples in the cvi\samples\tcp directory.

Now, as far as passing structures through DataSocket, you don't really want to try and pass the entire structure as a single data object. DataSocket is an ActiveX technology and being as such only supports the native datatypes associated with it, which includes variants. Now you could try packaging your structure into a variant and it would be transmitted back and forth fine, but you would have to be absolutely sure that any subscribing application to this data object knows the exact makeup of this variant, otherwise you will quickly run into compatibility problems, and on top of that the amount of programming and management of your data can get rather complex really quick. What I suggest you do instead is pass the main field of your structure as the actual data value for the datasocket, and then pass the rest of the fields in the structure as attributes of this data value making it relatively easy to obtain all of your structure's information.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 4
(3,229 Views)
I'm not sure that you answered my question. How do I share an array of structures across the datasocket? I don't know before run time how many elements this array will be.
0 Kudos
Message 3 of 4
(3,229 Views)
I didn't lay it out for you step-by-step or provide a cookbook example, but the last paragraph in my reply answers your question exactly.

The concepts in it can be applied to data known at development or run time, you will just have to construct the data objects on the server dynamically depending on what data it is you will need to send.

Again the two options are:

1) Creating a data object on the server for the main data item in the structure and then an attribute for the same object for each additional structure item.

2) Package a variant and send this as a single data item with no attributes via DataSocket.

Going the variant route is considerably tougher for the reasons I mentioned before, but the choice is yours.

If you decide
to go the route of splitting the structures into data object/attribute sets we do have an example that illustrates the concept at the following two links:

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&B02E52CD8D7D22568625687F005AE3EE&cat=279A3DDF188351A58625699100696455

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&5228C05FB18C24858625687F005AE3ED&cat=279A3DDF188351A58625699100696455

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 4 of 4
(3,229 Views)