linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* UDP message boundary
@ 2012-10-15  4:50 Randi Botse
  2012-10-17  3:24 ` Randi Botse
  2012-10-20 21:55 ` Hendrik Visage
  0 siblings, 2 replies; 6+ messages in thread
From: Randi Botse @ 2012-10-15  4:50 UTC (permalink / raw)
  To: linux-c-programming

Hi All

When using TCP socket, I loop send() or recv() until ALL the data has
been transmitted (or error, disconnect, etc.), because TCP socket
packet is transmitted in stream nature, maybe a byte, bytes or all
bytes in one transfer.

The UDP socket preserve message boundary which TCP socket doesn't.
Does this means single call to sendto() will processed by single call
recvfrom()?, and how about packet that exceeds UDP data MAX size?.

So in code, do I need to loop sendto() or recvfrom() to transmit the data?.

Example codes is:

char packet[100];
size_t nbytes = 0;
int ret;

while (nbytes < sizeof(packet)) {
    ret = recvfrom(socket, packet + nbytes, addr, 0,  sizeof(packet) - nbytes);
    if (ret <= 0) {
        /* deal with recvfrom() error */
    }
    nbytes += ret
}


Thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-21  9:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15  4:50 UDP message boundary Randi Botse
2012-10-17  3:24 ` Randi Botse
2012-10-19 14:15   ` Lorenzo Beretta
2012-10-19 15:03     ` Randi Botse
2012-10-20 21:55 ` Hendrik Visage
2012-10-21  9:46   ` Randi Botse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).