Hi,<br><br>I've been testing one code found on internet and it works smoothly. The code can be found at:<br><br><a href="http://20bits.com/articles/erlang-a-generalized-tcp-server/">http://20bits.com/articles/erlang-a-generalized-tcp-server/</a><br>
<br>Take a look at the code and compare it with your code. It will help in solving your problem.<br><br>About your code, it may be your code gets a bit confused by which connection belongs to which spawned thread and then releases an error which generates tcp_closed message. Nevertheless, I might be wrong. Better try to dump your tcp traffic and see where is the problem in the connections.<br>
<br>Cheers,<br>CGS<br><br><br><br><div class="gmail_quote">On Mon, Sep 5, 2011 at 6:59 PM, Reynaldo Baquerizo <span dir="ltr"><<a href="mailto:reynaldomic@gmail.com">reynaldomic@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I have a running application that consist in a supervisor and two<br>
generic servers, one of them wraps around odbc and the other handles<br>
tcp connections, a fragment of the relevant code is:<br>
<br>
<br>
init([]) -><br>
    process_flag(trap_exit, true),<br>
    {ok, ListenSocket} = gen_tcp:listen(Port, [binary, {packet, 0},<br>
                                                                     {reuseaddr, true},<br>
                                                                     {active, true}]),<br>
    proc_lib:spawn_link(?MODULE, acceptor, [ListenSocket])<br>
<br>
acceptor(ListenSocket) -><br>
    {ok, Socket} = gen_tcp:accept(ListenSocket),<br>
    error_logger:info_msg("New connection from ~p~n", [Socket]),<br>
    _Pid = proc_lib:spawn(?MODULE, acceptor, [ListenSocket]),<br>
    inet:setopts(Socket, [binary, {nodelay, true}, {active, true}]),<br>
    loop(Socket).<br>
<br>
loop(Socket) -><br>
    receive<br>
        {tcp, Socket, Data} -><br>
            error_logger:info_msg("Messaged received from ~p: ~p~n", [Socket, Data]),<br>
            comm_lib:handle_message(Socket, Data),<br>
            loop(Socket);<br>
        {tcp_closed, Socket} -><br>
            error_logger:info_msg("Device at ~p disconnected~n", [Socket]);<br>
        _Any -><br>
            %% skip this<br>
            loop(Socket)<br>
    end.<br>
<br>
So, I basically start a new  unlinked process for every new tcp<br>
connection. It works just fine for a couple hours but  then every tcp<br>
connection is dropped gradually with message "Device at ~p<br>
disconnected". The client will try to reconnect if connection is<br>
closed. The tcp connection should only terminate if remote end closes<br>
it or spawned proccess in the server crashes.<br>
<br>
After all connections were dropped, I can see with inet:i() that there<br>
are established connections but no logging!<br>
<br>
Can anyone give some insight or point to the right direction to debug this?<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br>