TCP proxy using gen_server tutorial (Part 1)

Vlad Dumitrescu (EAW) <>
Mon Mar 17 10:48:56 CET 2003


Very good initiative, and good work!

Some notes:

* If you start the gen_server giving it a name to register, then there will only be at most one instance of it available at all times. I think you meant to register with the name of the service module, in this case echo?

> 1) If I kill the accept process, it is not caught in handle_info
> and it takes down the entire gen_server.  I tried to trap_exit
> in tcp_proxy:start_link, but it just occurred to me I need to
> trap_exit where the accept process is spawned.   

* trap_exits has to be set on the gen_server process, and that means for example in tcp_proxy:init.

* There is a small error in handle_info({'EXIT' : the result of spawn_link should be stored in a Pid2, and that one used in the answer.
> 2) If I start the server like:  {ok, P2} = tcp_proxy:start_link(echo),
> and then erroneously call tcp_proxy:report_clients(P1) or any
> other function, the gen_server gets a badmatch, 

* Use the pid only if the server has no registered name; see first note too.

* The server goes down only because you don't catch the crashing gen_server:call. If you just add a 'catch', the tcp_proxy server will remain up.

> 3) When the server goes down, the existing clients remain
> connected.  I thought when a Listen socket was closed, all
> Accept sockets derived from it would automatically be closed.
> As it is any previously connected clients will still get serviced
> after the server is down (I'm not sure if this is good or bad).

* Here I'm not sure either how to do it. 

best regards,

More information about the erlang-questions mailing list