LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI TCP System callbacks

I have a tcp client who is based loosely on the tcp client example code, I have the program open the connection to the tcp server then enter an infinate loop the does ProcessSystemEvents(). I was relying on the general TCPCallback that I registered with I opened the TCP connection to alert me when data, the Callback would then call a function to serve the recieved data. The problem I encountered is sometimes the callbacks would stop occuring and the program would be stuck doing process system events and I would never know that data arrived even though using a network protocal analiser I see that windows TCP stack is recieving the data. Watching the network analizer I see the TCP window for my client getting smaller indicating that windows is recieving the packets and buffering them for the program to retrieve.

The quick fix I found is to move the tcp rx handler from the "case TCP_DATAREADY:" statement in the general tcp callback to the infinate loop along with the ProcessSystemEvents() (see psudo code).

Ex. Problematic way
//Main
main{
OpenTCPConnection

do{
ProcessSystemEvents()

}while(1)

}

//TCP Callback Function
TCPCallbackFunction{
switch (event)
        {
        case TCP_DATAREADY:
            ProcessTCPRx()
            break;

        case TCP_DISCONNECT:
            QUIT()
            break;
    }
}


Ex. Working Hack Way

//Main
main{
OpenTCPConnection

do{
ProcessSystemEvents()
ProcessTCPRx()

}while(1)

}

//TCPCallbackFunction{
switch (event)
        {
        case TCP_DATAREADY:
            break;
       
       case TCP_DISCONNECT:
            QUIT()
            break;
    }
}

I should mention that all this is happening inside a thread that my main app launches.

Has anyone else seen such behavoir? Is pooling the TCP system like this a good/bad idea?

Tyler
0 Kudos
Message 1 of 3
(3,811 Views)
Polling the TCP connection like you are doing is not a bad idea. You can read data by polling or using the callback depending on your application needs. I am not sure why your callbacks are not getting called after some time - it could be something in your ProcessTCPRx function. You should not block the TCP callback for a long time.
0 Kudos
Message 2 of 3
(3,794 Views)
So far pooling is having good results, I have not encountered any problems yet.

As for finding the source of the problem I have not found anything that seems like it could stop the TCP system from generating DataReady Callbacks. Iv been looking for more infromation on how CVI handles the callbacks but I have come up empty. I do use PostDeferredCallToThread in the application so that may be related somehow. Although it bugs me to leave something unexplained I have moved on to big better things.

Thanks for the Info Mohan
Tyler
0 Kudos
Message 3 of 3
(3,779 Views)