其实很简单 只是刚开始写 udpread()函数是这样的:
int CVICALLBACK UDPReadCallback (unsigned channel, int eventType, int errCode, void *callbackData)
{
int error = 0,
size;
unsigned char *msg = NULL;
if (eventType == UDP_DATAREADY)
{
// Pass NULL as the input buffer to determine the size of the arrived data.
size = UDPRead(channel, NULL, 0, UDP_DO_NOT_WAIT , NULL, NULL);
msg = calloc(size ,1);
// Read the waiting message into the allocated buffer.
size = UDPRead(channel, msg, size , UDP_DO_NOT_WAIT , NULL, NULL);
if(size<0)
{
return 0;
}
else
{
ProcessMsg(msg,size);
}
}
return 0;
} |