Hello,
I'm using LabWindows/CVI 2012 and I have to create a dll that passes data to/from LabVIEW (Call Library Function). The reason I am using a dll instead of LabVIEW for this functionality is that I have a lot of message processing to perform with variable sized UDP datagrams, etc. I really do not want to use the build in UDP Support Library calls in LabWindows/CVI and was hoping just to use ansi.c and winsock2 for portability unless someone informs me otherwise. Most of my code seems to work except I have spent several days trying to get the recvfrom and sendto functions to work at the same time.
My problem is that recvfrom is in an infinite loop. I have already tried setting the receive socket to non-blocking with no luck. I think the problem is that my far end application is sending datagrams at a rate that my dll cannot keep up. There is always data in the recv buffer so I never get to the sendto call below. I can post more, but this is the basic code (sorry, but the code is on a stand-alone not connected to Internet):
if (timeSinceLastRun >= 50ms) // far end is sending 2 datagrams every 100 ms
{
rcvSocket = OpenUdpSocket (&rcvAddr, localPort, rcvAddress, rcvNICAddress, rcvNICAddress); // in here I set the rcvSocket to Non-Blocking
sendSocket = OpenUdpSocket (&sendAddr, remotePort, sendAddress, sendNICAddress, sendNICAddress);
while (bytesRead = recvfrom (sendSocket, buff, maxBuffSize, sizeof (buff), 0, NULL, NULL)) > 0) // ALWAYS STUCK IN THIS LOOP
{
// decode data
}
// encode data
if ( sendto (sendSocket, buff, sizeoff(msg), 0, (struct sockaddr FAR *)&outSockaddr, sizeof (outSockaddr)) == 1) // NEVER GETS HERE !!
printf("sendto() error %d\n", WSAGetLastError());
closesocket(rcvSocket);
closesocket(sendSocket);
WSACleanup();
}
Any help including examples would be greatly appreciated.
RobL