Why would WiFiUDP::endPacket return error?

Hi everybody!

I have a sketch which contains a function called from loop() that does the following:

    memset(&pkg, 0, sizeof(pkg));
    pkg.cmd = REQ_ID_STREAM_INFO;
    pkg.payload.stream_info.width = camera.width();
    pkg.payload.stream_info.height = camera.height();
    Udp.beginPacket(ctx->ip, ctx->port);
    Udp.write((uint8_t *)&pkg, sizeof(pkg));
    Udp.endPacket();
     
              
    // frame proper
    memset(&pkg, 0, sizeof(pkg));
    pkg.cmd = REQ_ID_STREAM_FRAME;
    pkg.payload.frame_size = camera.frameSize();
    Udp.beginPacket(ctx->ip, ctx->port);
    Udp.write((uint8_t *)&pkg, sizeof(pkg));
    Udp.write(camera.raw(), 30);//camera.frameSize());
    Udp.endPacket(); // OCCASIONAL FAILURE HERE

The last line occasionally fails.

I've noticed it doesn't fail when I reduce the number of bytes written to the second frame or when I introduce a delay between two packets.

Should it be like that or is it just a coincidence?

Can I check somehow that the packet has been sent and I can feed Udp more data? Should I do it?

I'm using WEMOS D1 Mini Lite based on ESP8285, WiFi client mode.

The last line occasionally fails.

Your proof seems to be non-existent.

I've noticed it doesn't fail when I reduce the number of bytes written to the second frame

What do you mean by "second frame"? Reduce the number from what to what?

or when I introduce a delay between two packets.

What two packets? That code sends ONE packet.

Can I check somehow that the packet has been sent

The endPacket() method returns a value, so, yes, you can.

PaulS:
Your proof seems to be non-existent.
What do you mean by "second frame"? Reduce the number from what to what?
What two packets? That code sends ONE packet.
The endPacket() method returns a value, so, yes, you can.

The proof seems to be true as when I reduce packet length to 30 bytes (you can see the commented-out fragment there) the number of packets dropped reduces.

How do you mean ONE packet? I call beginPacket/endPacket two times. Is it going to be one packet?

I call beginPacket/endPacket two times.

I must have missed the scrollbars.