LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

UDPWrite in a loop. "A Windows Sockets function call returned an unexpected error."

Hello together,

 

i use UDP Support Library in NI CVI 9.0. When i wait for receiving a packet at the pc to send then a packet from the pc, the functions UDPRead and UDPWrite work fine. If i want to test the maximum throughput, i put the UDPWrite in a loop, but then an error occurs. It is "kUDP_UnexpectedWinsockError"

 

Error Popup:

"NON-FATAL RUN-TIME ERROR:   "main.c", line 53, col 22, thread id
0x00000C18:   Library function error (return value == -6822
[0xffffe55a]). A Windows Sockets function call returned an unexpected
error."

Line 53:

status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);

 

the whole loop:

while(1)
{
status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458); 
      counter++;

    if(counter>50)
    {
      break;
    }
    else{;}
}

 

The error occurs after 3-16 packets have been sent. If i step through the programm, no error occurs. So i guess its because the UDPWrite command is invoked too fast. pOutputBuffer has static data. I could use a delay in the loop, but then i dont know how to configure for maximal throughput.

Any ideas how to avoid this error?

 

Regards Florian

0 Kudos
Message 1 of 5
(3,400 Views)

Well, it is a non-fatal error, so your release code is quite at liberty to ignore it. UDP** is an unreliable protocol, so trying to run it flat out is bound to result in lost packets - a fact which your system must be designed to cope with. You could arrange for a handshake to occur between the two ends in order to synchronise but then you're making it look more and more like a TCP connection. Can you not use the TCP libraries instead?

 

JR

 

** UDP = Unreliable Data Packet Smiley Tongue

0 Kudos
Message 2 of 5
(3,389 Views)

I don't want to have a "reliable" communication. I run LwIP on a Microcontroller and want to test at which rate it can receive packets without errors/loss. So i thought of using something like 10k loops over sending UDP packets. If i recognize all 10k packets with wireshark, i know that they have been sent. In the Microcontroller i count the packets and now know how many have been dropped. Later i will process the packets if the information is correct, but then i have to slow down throughput to have enough time to process them.

 

So my aim is to use UDPWrite at maximum speed.

0 Kudos
Message 3 of 5
(3,385 Views)

I'd take a let 'er rip approach and only update the counter when the UDPwrite succeeds and continue to retry on the error to force packets out at the maximum rate.

 

I might also put the counter into the payload buffer as a packet number so you can see if they all arrive and in what sequence.

 

If ignoring any dropped or corrupt packets and "catching up next time" is not tolerable, then UDP is the wrong choice and best you can hope for is reinventing TCPIP poorly, in whcih case you need to just use TCPIP and be done with it.

 

--wally.

 

0 Kudos
Message 4 of 5
(3,346 Views)

Hello and thank you for your answer. Sorry that i reply a month later.

 

I dont know what you mean by "let 'er rip approach". Do you mean something like:

 

status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
if(status==0)
{
 counter++;
}

else

{

  Delay(0.00005);

}

 

I did not yet try to put the packet number in the payload, but there is just a 30 cm crossover cable between the two devices, no switch, no router. So the sequence should not be interruptet. And even if they arrive in chaos, i dont mind.

 

I have contacted the NI support 2 weeks ago, but no response yet.

 

I did some tests with a delay between the execution of UDPWrite(). The code:

 

float time = 0.0;

 for(i = 1; i < 1000; i++)
 {
  status = UDPWrite (channel, 60100, "192.168.1.10", pOutputBuffer, 1458);
  time = 1.0 / i;
  Delay(time);
 }

 

The results:

For i between 1 and 1000: no error, the speed of the last ten packets was about 6.5 MBit/s

For i between 1000 and 2000: error occured at i = 1585 (variable time in Delay was 0.0006313), the speed of the last ten packets was about 8 MBit/s

 

Then i put some constant values in Delay and ran 100 UDPWrite iterations:

Delay(0.0006): 7.48 MBit/s

Delay(0.0001): 10.7 MBit/s

Delay(0.00001): error occured at i=31, speed of 31 packets was 12.0 MBit/s

Delay(0.00008): 100 of 100 packets, speed 10.9 MBit/s

Delay(0.00005): error at i=41, speed of 41 packets 11.1 MBit/s

0 Kudos
Message 5 of 5
(3,245 Views)