[erlang-questions] Unbuffered/blocking gen_tcp send

Matthias Lang <>
Fri Apr 17 16:16:05 CEST 2009


Hi,

> Hi, is it possible to have gen_tcp:send block until the receiver has
> received the package using gen_tcp:recv? For instance if the sender
> transmits packages which takes long time to process for the receiver.

gen_tcp:send can't do this for you. More generally, TCP doesn't provide
that service. (And: TCP's interface upwards is streams, not packets. The
packets you get from the {packet, N} modes in gen_tcp are added by Erlang
on top of TCP)

> I've been experimenting with the buffer sizes but even setting to sndbuf
> and recbuf to 1 won't make gen_tcp:send to block, unless the packages
> are large (1Kb+).

> I guess it would be possible to manually implement flow-control by
> acknowledging each package but I would rather just have gen_tcp:send block.

You've got the right idea. TCP has flow control, but it can't be
controlled at the fine level you would like it to, i.e. down to
whether a given "packet" has been received by an application at the
other end or not. If you want that, you have to implement it yourself
on top of TCP.

Matthias



More information about the erlang-questions mailing list