LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Example of ConnectToTCPServer function's void *callbackData parameter?

I am trying to use the ConnectToTCPServer function's void *callbackData parameter as a method of determining which of several tcpip servers has reponded to my client.
 
I am using the function as shown below:
 
[...]
 
 had_err = ConnectToTCPServer(&interface[portid].tcpip_handle,
        interface[portid].socket,
        interface[portid].ip_address,
        Net2SerialCallback,
        (void *) &test,
        //(void *) &portid,
        interface[portid].timeout_msec
       );
[...]
 
And my call back function is something like below:
 
int CVICALLBACK Net2SerialCallback (unsigned handle, int event, int error, void *callbackData) 
{
 
    //I
 
}
0 Kudos
Message 1 of 4
(4,215 Views)

Sorry, the post was sent before I had finished it.

I am trying to use the "void *callbackData" parameter to hold the value that was passed in that parameter in ConnectToTCPServer.

I have not been successful.  It appears that callbackData always contains the same values (junk?) no matter what value I pass in ConnectToTCPServer.

Has anyone ever successfully used the callbackData parameter?

 

0 Kudos
Message 2 of 4
(4,214 Views)

You need to make sure that your variable test is not a local variable. Because if it is, then the address that you're storing in the callback data is just a stack address that will become invalid as soon as the function in which you connected to the server exits.

If you're already using a global variable, then let me know, and we'll see if we can investigate further.

Luis

0 Kudos
Message 3 of 4
(4,195 Views)

Thanks Luis.  You are correct.  My normal variable is global, but the test variable I experimented with was not.  That took care of my problem.

Thank you very much.  I appreciate your help.

0 Kudos
Message 4 of 4
(4,189 Views)