From: Randi Botse <nightdecoder@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: UDP message boundary
Date: Mon, 15 Oct 2012 11:50:50 +0700 [thread overview]
Message-ID: <CAA6iF_7Hmu4c2FyGFRUw12QxK=t_tMvyu_xhMUjFGe7fCTxw5Q@mail.gmail.com> (raw)
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
next reply other threads:[~2012-10-15 4:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-15 4:50 Randi Botse [this message]
2012-10-17 3:24 ` UDP message boundary 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAA6iF_7Hmu4c2FyGFRUw12QxK=t_tMvyu_xhMUjFGe7fCTxw5Q@mail.gmail.com' \
--to=nightdecoder@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).