gen_udp:recv()
zxq9
zxq9@REDACTED
Tue Apr 6 15:12:15 CEST 2021
Hi Avinash,
On 2021/04/05 22:42, Avinash Dhumane wrote:
> I am taking a short-cut to inquire this, by posting to you all (than
> going through relevant documentation).
Oh! The humanity!
> Is gen_udp:recv() to be invoked per datagram, or can it return a binary
> of multiple datagrams concatenated?
It returns a single datagram with some meta about the transmission
(port, address, etc.).
> I am asking this because there is Length to recv(), and I don’t
> understand why it is there. Should it specify the length of expected
> datagram? What if the datagrams of variable length? Should it, then,
> specify the maximum length?
This goes back to memory allocation issues when you are allocating
memory manually. How much is the max size you want to receive might be
based on the size of the buffer you're willing to set aside for the
incoming data -- not the kind of thing people have to contemplate as
carefully as they did in earlier eras of networking.
There are some other lower level UDP dials and knobs that allow you to
peek at the size and UDP headers and whatnot to figure out what a
reasonable balance between getting an entire datagram, being safe, and
not being wasteful might be -- and typically you know what protocol
you're working with.
Anyway, in Erlang this is pretty much irrelevant. The common way to
receive UDP traffic (and TCP traffic, for that matter) is to leave all
the low level stuff to the runtime and inside your code just receive it
as an Erlang message and not deal with udp:recv/2,3 at all.
-Craig
More information about the erlang-questions
mailing list