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

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Fri Jun 15 09:44:23 CEST 2007

jm wrote:
> 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?

That's what it does. I guess it also tells the port
which process to monitor. When the controlling process
dies, the port is closed.

> 2) What happens if I don't call it to transfer
> ownership and the new or another process attempts
> to write to the socket?

Other processes can write to the socket. This is an
optimization, and also quite convenient if you have 
a registered port - that means you can use port_command()
on a registered port, and essentially make your own BIFs.

> 3) Can a process take ownership by calling this
> itself when not already the owner, ie steal ownership?

No, controlling_process/2 must be called from the 
current controlling process.

Ulf W

More information about the erlang-questions mailing list