[erlang-questions] How to write a TCP server in Erlang?

jm jeffm@REDACTED
Fri Jun 15 03:07:07 CEST 2007

Ulf Wiger wrote:

> Oh, and you should call gen_tcp:controlling_process(Sock, Worker)
> on the server side. It doesn't matter in this limited example, since
> you explicitly do receive on a passive socket, but it's still the
> right thing to do, I think.

Can you out line the purpose of gen_tcp:controlling_process/2 for me.
Much of the example code I've seen doesn't use it. In some code I've
written I had to transfer ownership of the socket from one process to
another. I came across this in my reading of the manual and added it in,
calling it from the old owner saying that the new process was the
controlling process now.

My questions are, reasonably basic just clarify my understanding,

1) What effect does gen_tcp:controlling_process/2 have besides changing
who recieves the incoming packets?
2) What happens if I don't call it to transfer ownership and the new or
another process attempts to write to the socket?
3) Can a process take ownership by calling this itself when not already
the owner, ie steal ownership?


More information about the erlang-questions mailing list