[erlang-questions] UDP questions

Paul Peregud <>
Wed Jan 27 16:43:37 CET 2016

This boils down to UDP being datagram protocol. It can't fragment
packets by design, since it does not assume that it is operating on
stream of data. Also, every packet is treated as something that can be

So it may get dropped by anyone: network router, network adapter,
kernel, or BEAM. On both sending and receiving side. As for reasons
for dropping - packet is too big to fit into single ethernet frame,
buffer (of any device or program) being full, connection being
congested. In general UDP user needs to take care of all those things
by himself.

On bright side - UDP is cheaper and is better in some circumstances
than TCP. I'm not aware though of any libraries that simplify UDP -
but I'm not an expert at all.

On Wed, Jan 27, 2016 at 4:27 PM, Joe Armstrong <> wrote:
> Hello,
> I have a simple UDP client/server
> The server is on a fixed port 4567 - I open it like this
>     {ok, Socket} = gen_udp:open(4567, [binary]),
> then wait for registrations
>     receive
> {udp, Socket, _Ip, _Port, <<"register">>) ->
> Clients do this:
>      {ok, Socket} = gen_udp:open(0, [binary]),
>      gen_udp:send(Socket, "localhost", 44567, <<"register">>),
>      ...
> I'm testing on "localhost"
> After registration the processes send binaries to each other
> This works fine for small binaries but gen_udp:send fails  with
> {error,emsgsize} for large binaries
> So I have a few questions:
>     1) Can I find out the max binary size that can be sent/received?
>     2) Can I increase the max size?
>     3) Is there a guaranteed minimum packet length that will not be fragemented?
>     3) Can received packets be fragmented - TCP has a  {packet,N}
>        option and some built-in defragmentation, what's the story for
>        UDP?
> I think I know the answers to these but I'm not really sure - could somebody
> who really knows enlighten me?
> Thanks
> /Joe
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions

Best regards,
Paul Peregud

More information about the erlang-questions mailing list